Remove datetime_range icon and library

Created on 19 December 2023, 12 months ago
Updated 11 January 2024, 11 months ago

Problem/Motivation

Hi!

After the field_type_category API has landed, core/core.field_type_category.yml gefines the category name "date_time" for some fields.

Then, both:
- TimestampItem.php (Drupal\Core\Field\Plugin\Field\FieldType),
- DateTimeItem.php (datetime\Plugin\Field\FieldType),
- and DateRangeItem.php (datetime_range\Plugin\Field\FieldType)
in their annotation it is used category = "date_time",.

However, in the module datetime_range, in its .module file we find:

/**
 * Implements hook_field_type_category_info_alter().
 */
function datetime_range_field_type_category_info_alter(&$definitions) {
  // The `datetime_range` field type belongs in the `general` category, so the
  // libraries need to be attached using an alter hook.
  $definitions[FieldTypeCategoryManagerInterface::FALLBACK_CATEGORY]['libraries'][] = 'datetime_range/drupal.datetime_range-icon';
}

using the wrong category and it should be 'date_time' instead, so the whole hook is not needed and we can remove it (commenting it does not make any impact in the 'add field' page of any content type) from the .module file and also the library and css involved as they are not used anymore.

In addition, if we take a look at FieldStorageAddForm() (line 346), we have:

    $form['#attached']['library'] = [
      'field_ui/drupal.field_ui',
      'field_ui/drupal.field_ui.manage_fields',
      'core/drupal.ajax',
    ];

and in the library 'field_ui/drupal.field_ui.manage_fields that calls field_ui/css/field_ui.icons.theme.css we can find the proper css that is used for the fields that are grouped under the category 'date_time':

.field-icon-date_time {}

In the same file, we find as well

.field-icon-daterange {}

but it is not used anymore as 'date_time' is the category in all the fields and can be removed too.

Steps to reproduce

Comment the whole function in the .module, then CR and see the icon is still there (in the "add new field" page under any CT bundle admin/structure/types/manage/<bundle>/fields/add-field); therefore any mention to 'daterange' css icon is not used.

Proposed resolution

- Remove the datetime_range_field_type_category_info_alter() on the .module file
- Remove the datetime_range.libraries.yml file as it it might not be needed.
- Remove the css folder, as the files inside are not needed (duplicated)
- Update the Drupal\KernelTests\Core\Theme\Stable9LibraryOverrideTest class and remove datetime_range/drupal.datetime_range-icon from there.
- Remove the .field-icon-daterange from field_ui/css/field_ui.icons.theme.css as it is not used either.

Best

🐛 Bug report
Status

Fixed

Version

10.2

Component
Datetime 

Last updated 3 days ago

Created by

🇧🇪Belgium gorkagr

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024