diff --git a/core/modules/datetime_range/datetime_range.module b/core/modules/datetime_range/datetime_range.module index 0a505c30c75b02d6d5f31c09afa67691b5e36b80..c0be2a2089d8c0aeffabc89aa8bad47918792dd6 100644 --- a/core/modules/datetime_range/datetime_range.module +++ b/core/modules/datetime_range/datetime_range.module @@ -5,13 +5,8 @@ * Field hooks to implement a datetime field that stores a start and end date. */ -use Drupal\Core\Entity\Display\EntityViewDisplayInterface; use Drupal\Core\Url; use Drupal\Core\Routing\RouteMatchInterface; -use Drupal\datetime_range\DateTimeRangeConstantsInterface; -use Drupal\datetime_range\Plugin\Field\FieldFormatter\DateRangeCustomFormatter; -use Drupal\datetime_range\Plugin\Field\FieldFormatter\DateRangeDefaultFormatter; -use Drupal\datetime_range\Plugin\Field\FieldFormatter\DateRangePlainFormatter; /** * Implements hook_help(). @@ -32,36 +27,3 @@ function datetime_range_help($route_name, RouteMatchInterface $route_match) { return $output; } } - -/** - * Implements hook_ENTITY_TYPE_presave() for entity_view_display entities. - * - * @todo Remove this when datetime_range_post_update_from_to_configuration is removed. - */ -function datetime_range_entity_view_display_presave(EntityViewDisplayInterface $entity_view_display): void { - /** @var \Drupal\Core\Field\FormatterPluginManager $field_formatter_manager */ - $field_formatter_manager = \Drupal::service('plugin.manager.field.formatter'); - - foreach ($entity_view_display->getComponents() as $name => $component) { - if (empty($component['type'])) { - continue; - } - - $plugin_definition = $field_formatter_manager->getDefinition($component['type'], FALSE); - $daterange_formatter_classes = [ - DateRangeCustomFormatter::class, - DateRangeDefaultFormatter::class, - DateRangePlainFormatter::class, - ]; - - if (!in_array($plugin_definition['class'], $daterange_formatter_classes, FALSE)) { - continue; - } - - if (!isset($component['settings']['from_to'])) { - // Existing daterange formatters don't have 'from_to'. - $component['settings']['from_to'] = DateTimeRangeConstantsInterface::BOTH; - $entity_view_display->setComponent($name, $component); - } - } -} diff --git a/core/modules/media/media.module b/core/modules/media/media.module index 7b9f3d40aacd6837e01c8e94b0d287d1ba32521f..9267942e9e936cd5365e9d826fe951135ffba671 100644 --- a/core/modules/media/media.module +++ b/core/modules/media/media.module @@ -7,7 +7,6 @@ use Drupal\Component\Plugin\DerivativeInspectionInterface; use Drupal\Core\Access\AccessResult; -use Drupal\Core\Entity\Display\EntityViewDisplayInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Field\FieldTypeCategoryManagerInterface; use Drupal\Core\Form\FormStateInterface; @@ -18,7 +17,6 @@ use Drupal\Core\Template\Attribute; use Drupal\Core\Url; use Drupal\field\FieldConfigInterface; -use Drupal\media\MediaConfigUpdater; use Drupal\media\Plugin\media\Source\OEmbedInterface; use Drupal\views\ViewExecutable; @@ -364,15 +362,6 @@ function media_entity_type_alter(array &$entity_types) { } } -/** - * Implements hook_ENTITY_TYPE_presave() for entity_view_display. - */ -function media_entity_view_display_presave(EntityViewDisplayInterface $view_display): void { - $config_updater = \Drupal::classResolver(MediaConfigUpdater::class); - assert($config_updater instanceof MediaConfigUpdater); - $config_updater->processOembedEagerLoadField($view_display); -} - /** * Implements hook_form_FORM_ID_alter(). */ diff --git a/core/modules/media/src/MediaConfigUpdater.php b/core/modules/media/src/MediaConfigUpdater.php deleted file mode 100644 index 8544e880070a1f1e92516d88ac51b5f9fb894dc4..0000000000000000000000000000000000000000 --- a/core/modules/media/src/MediaConfigUpdater.php +++ /dev/null @@ -1,72 +0,0 @@ -<?php - -namespace Drupal\media; - -use Drupal\Core\Entity\Display\EntityViewDisplayInterface; - -/** - * Provides a BC layer for modules providing old configurations. - * - * @internal - * This class is only meant to fix outdated media configuration and its - * methods should not be invoked directly. It will be removed once all the - * associated updates have been removed. - */ -class MediaConfigUpdater { - - /** - * Flag determining whether deprecations should be triggered. - * - * @var bool - */ - private $deprecationsEnabled = FALSE; - - /** - * Stores which deprecations were triggered. - * - * @var bool - */ - private $triggeredDeprecations = []; - - /** - * Sets the deprecations enabling status. - * - * @param bool $enabled - * Whether deprecations should be enabled. - */ - public function setDeprecationsEnabled(bool $enabled): void { - $this->deprecationsEnabled = $enabled; - } - - /** - * Processes oembed type fields. - * - * @param \Drupal\Core\Entity\Display\EntityViewDisplayInterface $view_display - * The view display. - * - * @return bool - * Whether the display was updated. - */ - public function processOembedEagerLoadField(EntityViewDisplayInterface $view_display): bool { - $changed = FALSE; - - foreach ($view_display->getComponents() as $field => $component) { - if (array_key_exists('type', $component) - && ($component['type'] === 'oembed') - && !array_key_exists('loading', $component['settings'])) { - $component['settings']['loading']['attribute'] = 'eager'; - $view_display->setComponent($field, $component); - $changed = TRUE; - } - } - - $deprecations_triggered = &$this->triggeredDeprecations['3212351'][$view_display->id()]; - if ($this->deprecationsEnabled && $changed && !$deprecations_triggered) { - $deprecations_triggered = TRUE; - @trigger_error(sprintf('The oEmbed loading attribute update for view display "%s" is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Profile, module and theme provided configuration should be updated. See https://www.drupal.org/node/3275103', $view_display->id()), E_USER_DEPRECATED); - } - - return $changed; - } - -} diff --git a/core/modules/node/node.module b/core/modules/node/node.module index c32ab74fcc6e754a1b38d0a85a638737b943652c..ed4bf43a3cf8ce5764980f7e5d613fded7964333 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -1216,18 +1216,3 @@ function node_comment_delete($comment) { function node_config_translation_info_alter(&$info) { $info['node_type']['class'] = 'Drupal\node\ConfigTranslation\NodeTypeMapper'; } - -/** - * Implements hook_ENTITY_TYPE_presave(). - */ -function node_node_type_presave(NodeTypeInterface $node_type) { - // Content types' `help` and `description` fields must be stored as NULL - // at the config level if they are empty. - // @see node_post_update_set_node_type_description_and_help_to_null() - if (trim($node_type->getDescription()) === '') { - $node_type->set('description', NULL); - } - if (trim($node_type->getHelp()) === '') { - $node_type->set('help', NULL); - } -} diff --git a/core/modules/responsive_image/responsive_image.module b/core/modules/responsive_image/responsive_image.module index b4cfdee53bcfd30db4c5fd74fd0fc8974bef8011..5625cbbea05bc78371c5c3dad46e5ece816c966b 100644 --- a/core/modules/responsive_image/responsive_image.module +++ b/core/modules/responsive_image/responsive_image.module @@ -5,14 +5,12 @@ * Responsive image display formatter for image fields. */ -use Drupal\Core\Entity\Display\EntityViewDisplayInterface; use Drupal\Core\Url; use Drupal\Core\Template\Attribute; use Drupal\Core\Logger\RfcLogLevel; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\image\Entity\ImageStyle; use Drupal\responsive_image\Entity\ResponsiveImageStyle; -use Drupal\responsive_image\ResponsiveImageConfigUpdater; use Drupal\responsive_image\ResponsiveImageStyleInterface; use Drupal\breakpoint\BreakpointInterface; @@ -542,12 +540,3 @@ function responsive_image_library_info_alter(array &$libraries, $module) { $libraries['drupal.ajax']['dependencies'][] = 'responsive_image/ajax'; } } - -/** - * Implements hook_ENTITY_TYPE_presave() for entity_view_display. - */ -function responsive_image_entity_view_display_presave(EntityViewDisplayInterface $view_display): void { - /** @var \Drupal\responsive_image\ResponsiveImageConfigUpdater $config_updater */ - $config_updater = \Drupal::classResolver(ResponsiveImageConfigUpdater::class); - $config_updater->processResponsiveImageField($view_display); -} diff --git a/core/modules/responsive_image/src/Entity/ResponsiveImageStyle.php b/core/modules/responsive_image/src/Entity/ResponsiveImageStyle.php index c0f35e346675315e5fe54a1b3bb11a5c70797f86..31589a64a6511a8434979070ef7a19dc8ff4b7d0 100644 --- a/core/modules/responsive_image/src/Entity/ResponsiveImageStyle.php +++ b/core/modules/responsive_image/src/Entity/ResponsiveImageStyle.php @@ -3,9 +3,7 @@ namespace Drupal\responsive_image\Entity; use Drupal\Core\Config\Entity\ConfigEntityBase; -use Drupal\Core\Entity\EntityStorageInterface; use Drupal\image\Entity\ImageStyle; -use Drupal\responsive_image\ResponsiveImageConfigUpdater; use Drupal\responsive_image\ResponsiveImageStyleInterface; /** @@ -112,15 +110,6 @@ public function __construct(array $values, $entity_type_id = 'responsive_image_s parent::__construct($values, $entity_type_id); } - /** - * {@inheritdoc} - */ - public function preSave(EntityStorageInterface $storage) { - parent::preSave($storage); - $config_updater = \Drupal::classResolver(ResponsiveImageConfigUpdater::class); - $config_updater->orderMultipliersNumerically($this); - } - /** * {@inheritdoc} */ diff --git a/core/modules/responsive_image/src/ResponsiveImageConfigUpdater.php b/core/modules/responsive_image/src/ResponsiveImageConfigUpdater.php deleted file mode 100644 index a920798b5bffe7de90c02903737e3cf2ac9ef893..0000000000000000000000000000000000000000 --- a/core/modules/responsive_image/src/ResponsiveImageConfigUpdater.php +++ /dev/null @@ -1,105 +0,0 @@ -<?php - -namespace Drupal\responsive_image; - -use Drupal\Core\Entity\Display\EntityViewDisplayInterface; - -/** - * Provides a BC layer for modules providing old configurations. - * - * @internal - * This class is only meant to fix outdated responsive image configuration and - * its methods should not be invoked directly. - */ -final class ResponsiveImageConfigUpdater { - - /** - * Flag determining whether deprecations should be triggered. - * - * @var bool - */ - private $deprecationsEnabled = TRUE; - - /** - * Stores which deprecations were triggered. - * - * @var bool - */ - private $triggeredDeprecations = []; - - /** - * Sets the deprecations enabling status. - * - * @param bool $enabled - * Whether deprecations should be enabled. - */ - public function setDeprecationsEnabled(bool $enabled): void { - $this->deprecationsEnabled = $enabled; - } - - /** - * Re-order mappings by breakpoint ID and descending numeric multiplier order. - * - * @param \Drupal\responsive_image\ResponsiveImageStyleInterface $responsive_image_style - * The responsive image style - * - * @return bool - * Whether the responsive image style was updated. - * - * TODO: when removing this, evaluate if we need to keep it permanently - * to support an upgrade path (migration) from Drupal 7 picture module. - */ - public function orderMultipliersNumerically(ResponsiveImageStyleInterface $responsive_image_style): bool { - $changed = FALSE; - - $original_mapping_order = $responsive_image_style->getImageStyleMappings(); - $responsive_image_style->removeImageStyleMappings(); - foreach ($original_mapping_order as $mapping) { - $responsive_image_style->addImageStyleMapping($mapping['breakpoint_id'], $mapping['multiplier'], $mapping); - } - if ($responsive_image_style->getImageStyleMappings() !== $original_mapping_order) { - $changed = TRUE; - } - - $deprecations_triggered = &$this->triggeredDeprecations['3267870'][$responsive_image_style->id()]; - if ($this->deprecationsEnabled && $changed && !$deprecations_triggered) { - $deprecations_triggered = TRUE; - @trigger_error(sprintf('The responsive image style multiplier re-ordering update for "%s" is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Profile, module and theme provided Responsive Image configuration should be updated. See https://www.drupal.org/node/3274803', $responsive_image_style->id()), E_USER_DEPRECATED); - } - - return $changed; - } - - /** - * Processes responsive image type fields. - * - * @param \Drupal\Core\Entity\Display\EntityViewDisplayInterface $view_display - * The view display. - * - * @return bool - * Whether the display was updated. - */ - public function processResponsiveImageField(EntityViewDisplayInterface $view_display): bool { - $changed = FALSE; - - foreach ($view_display->getComponents() as $field => $component) { - if (isset($component['type']) - && $component['type'] === 'responsive_image' - && !array_key_exists('image_loading', $component['settings']) - ) { - $component['settings']['image_loading']['attribute'] = 'eager'; - $view_display->setComponent($field, $component); - $changed = TRUE; - } - } - - $deprecations_triggered = &$this->triggeredDeprecations['3192234'][$view_display->id()]; - if ($this->deprecationsEnabled && $changed && !$deprecations_triggered) { - $deprecations_triggered = TRUE; - @trigger_error(sprintf('The responsive image loading attribute update for "%s" is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Configuration should be updated. See https://www.drupal.org/node/3279032', $view_display->id()), E_USER_DEPRECATED); - } - - return $changed; - } - -} diff --git a/core/modules/taxonomy/taxonomy.module b/core/modules/taxonomy/taxonomy.module index e2e3ac143c13a36f23e25f2aedef9473e87ea0dd..e98b465cc3eaf732054e6a302ef765e1cda01097 100644 --- a/core/modules/taxonomy/taxonomy.module +++ b/core/modules/taxonomy/taxonomy.module @@ -11,7 +11,6 @@ use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Url; use Drupal\taxonomy\Entity\Term; -use Drupal\taxonomy\VocabularyInterface; /** * Implements hook_help(). @@ -295,15 +294,3 @@ function taxonomy_taxonomy_term_delete(Term $term) { /** * @} End of "defgroup taxonomy_index". */ - -/** - * Implements hook_ENTITY_TYPE_presave(). - */ -function taxonomy_taxonomy_vocabulary_presave(VocabularyInterface $vocabulary) { - // Vocabularies' `description` field must be stored as NULL at the config - // level if it is empty. - // @see taxonomy_post_update_set_vocabulary_description_to_null() - if (trim($vocabulary->getDescription()) === '') { - $vocabulary->set('description', NULL); - } -} diff --git a/core/modules/views/src/ViewsConfigUpdater.php b/core/modules/views/src/ViewsConfigUpdater.php index d1eaddbb1d9d750af4251cb9f3c557a7ec6b7aa1..5e80b06f8b0069aa6039c818fa378807c89f982d 100644 --- a/core/modules/views/src/ViewsConfigUpdater.php +++ b/core/modules/views/src/ViewsConfigUpdater.php @@ -3,13 +3,10 @@ namespace Drupal\views; use Drupal\Component\Plugin\PluginManagerInterface; -use Drupal\Core\Cache\Cache; use Drupal\Core\Config\TypedConfigManagerInterface; use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Drupal\Core\Entity\EntityFieldManagerInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; -use Drupal\Core\Field\Plugin\Field\FieldFormatter\TimestampFormatter; -use Drupal\Core\Language\LanguageInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -54,13 +51,6 @@ class ViewsConfigUpdater implements ContainerInjectionInterface { */ protected $formatterPluginManager; - /** - * An array of helper data for the multivalue base field update. - * - * @var array - */ - protected $multivalueBaseFieldsUpdateTableInfo; - /** * Flag determining whether deprecations should be triggered. * @@ -136,91 +126,12 @@ public function setDeprecationsEnabled($enabled) { * Whether the view was updated. */ public function updateAll(ViewEntityInterface $view) { - return $this->processDisplayHandlers($view, FALSE, function (&$handler, $handler_type, $key, $display_id) use ($view) { + return $this->processDisplayHandlers($view, FALSE, function (&$handler, $handler_type, $key, $display_id) { $changed = FALSE; - if ($this->processResponsiveImageLazyLoadFieldHandler($handler, $handler_type, $view)) { - $changed = TRUE; - } - if ($this->processTimestampFormatterTimeDiffUpdateHandler($handler, $handler_type)) { - $changed = TRUE; - } - if ($this->processRevisionFieldHyphenFix($view)) { - $changed = TRUE; - } - if ($this->processDefaultArgumentSkipUrlUpdate($handler, $handler_type)) { - $changed = TRUE; - } - if ($this->processDefaultPagerHeadingUpdate($handler, $handler_type)) { - $changed = TRUE; - } - if ($this->addLabelIfMissing($view)) { - $changed = TRUE; - } return $changed; }); } - /** - * Adds a label to views which don't have one. - * - * @param \Drupal\views\ViewEntityInterface $view - * The view to update. - * - * @return bool - * Whether the view was updated. - */ - public function addLabelIfMissing(ViewEntityInterface $view): bool { - if (!$view->get('label')) { - $view->set('label', $view->id()); - return TRUE; - } - return FALSE; - } - - /** - * Add lazy load options to all responsive_image type field configurations. - * - * @param \Drupal\views\ViewEntityInterface $view - * The View to update. - * - * @return bool - * Whether the view was updated. - */ - public function needsResponsiveImageLazyLoadFieldUpdate(ViewEntityInterface $view): bool { - return $this->processDisplayHandlers($view, TRUE, function (&$handler, $handler_type) use ($view) { - return $this->processResponsiveImageLazyLoadFieldHandler($handler, $handler_type, $view); - }); - } - - /** - * Processes responsive_image type fields. - * - * @param array $handler - * A display handler. - * @param string $handler_type - * The handler type. - * @param \Drupal\views\ViewEntityInterface $view - * The View being updated. - * - * @return bool - * Whether the handler was updated. - */ - protected function processResponsiveImageLazyLoadFieldHandler(array &$handler, string $handler_type, ViewEntityInterface $view): bool { - $changed = FALSE; - - // Add any missing settings for lazy loading. - if (($handler_type === 'field') - && isset($handler['plugin_id'], $handler['type']) - && $handler['plugin_id'] === 'field' - && $handler['type'] === 'responsive_image' - && !isset($handler['settings']['image_loading'])) { - $handler['settings']['image_loading'] = ['attribute' => 'eager']; - $changed = TRUE; - } - - return $changed; - } - /** * Processes all display handlers. * @@ -281,343 +192,4 @@ protected function processDisplayHandlers(ViewEntityInterface $view, $return_on_ return $changed; } - /** - * Add eager load option to all oembed type field configurations. - * - * @param \Drupal\views\ViewEntityInterface $view - * The View to update. - * - * @return bool - * Whether the view was updated. - */ - public function needsOembedEagerLoadFieldUpdate(ViewEntityInterface $view) { - return $this->processDisplayHandlers($view, TRUE, function (&$handler, $handler_type) use ($view) { - return $this->processOembedEagerLoadFieldHandler($handler, $handler_type, $view); - }); - } - - /** - * Processes oembed type fields. - * - * @param array $handler - * A display handler. - * @param string $handler_type - * The handler type. - * @param \Drupal\views\ViewEntityInterface $view - * The View being updated. - * - * @return bool - * Whether the handler was updated. - */ - protected function processOembedEagerLoadFieldHandler(array &$handler, string $handler_type, ViewEntityInterface $view): bool { - $changed = FALSE; - - // Add any missing settings for lazy loading. - if (($handler_type === 'field') - && isset($handler['plugin_id'], $handler['type']) - && $handler['plugin_id'] === 'field' - && $handler['type'] === 'oembed' - && !array_key_exists('loading', $handler['settings'])) { - $handler['settings']['loading'] = ['attribute' => 'eager']; - $changed = TRUE; - } - - $deprecations_triggered = &$this->triggeredDeprecations['3212351'][$view->id()]; - if ($this->deprecationsEnabled && $changed && !$deprecations_triggered) { - $deprecations_triggered = TRUE; - @trigger_error(sprintf('The oEmbed loading attribute update for view "%s" is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Profile, module and theme provided configuration should be updated. See https://www.drupal.org/node/3275103', $view->id()), E_USER_DEPRECATED); - } - - return $changed; - } - - /** - * Updates the timestamp fields settings by adding time diff and tooltip. - * - * @param \Drupal\views\ViewEntityInterface $view - * The View to update. - * - * @return bool - * Whether the view was updated. - */ - public function needsTimestampFormatterTimeDiffUpdate(ViewEntityInterface $view): bool { - return $this->processDisplayHandlers($view, TRUE, function (array &$handler, string $handler_type): bool { - return $this->processTimestampFormatterTimeDiffUpdateHandler($handler, $handler_type); - }); - } - - /** - * Processes timestamp fields settings by adding time diff and tooltip. - * - * @param array $handler - * A display handler. - * @param string $handler_type - * The handler type. - * - * @return bool - * Whether the handler was updated. - */ - protected function processTimestampFormatterTimeDiffUpdateHandler(array &$handler, string $handler_type): bool { - if ($handler_type === 'field' && isset($handler['type'])) { - $plugin_definition = $this->formatterPluginManager->getDefinition($handler['type'], FALSE); - // Check also potential plugins extending TimestampFormatter. - if (!$plugin_definition || !is_a($plugin_definition['class'], TimestampFormatter::class, TRUE)) { - return FALSE; - } - - if (!isset($handler['settings']['tooltip']) || !isset($handler['settings']['time_diff'])) { - $handler['settings'] += $plugin_definition['class']::defaultSettings(); - // Existing timestamp formatters don't have tooltip. - $handler['settings']['tooltip'] = [ - 'date_format' => '', - 'custom_date_format' => '', - ]; - return TRUE; - } - } - return FALSE; - } - - /** - * Replaces hyphen on historical data (revision) fields. - * - * This replaces hyphens with double underscores in twig assertions. - * - * @param \Drupal\views\ViewEntityInterface $view - * The view entity. - * - * @return bool - * Whether the handler was updated. - * - * @see https://www.drupal.org/project/drupal/issues/2831233 - */ - public function processRevisionFieldHyphenFix(ViewEntityInterface $view): bool { - // Regex to search only for token with machine name '-revision_id'. - $old_part = '/{{([^}]+)(-revision_id)/'; - $new_part = '{{$1__revision_id'; - $old_field = '-revision_id'; - $new_field = '__revision_id'; - /** @var \Drupal\views\ViewEntityInterface $view */ - $is_update = FALSE; - $displays = $view->get('display'); - foreach ($displays as &$display) { - if (isset($display['display_options']['fields'])) { - foreach ($display['display_options']['fields'] as $field_name => $field) { - if (!empty($field['alter']['text'])) { - // Fixes replacement token references in rewritten fields. - $alter_text = $field['alter']['text']; - if (preg_match($old_part, $alter_text) === 1) { - $is_update = TRUE; - $field['alter']['text'] = preg_replace($old_part, $new_part, $alter_text); - } - } - - if (!empty($field['alter']['path'])) { - // Fixes replacement token references in link paths. - $alter_path = $field['alter']['path']; - if (preg_match($old_part, $alter_path) === 1) { - $is_update = TRUE; - $field['alter']['path'] = preg_replace($old_part, $new_part, $alter_path); - } - } - - if (str_contains($field_name, $old_field)) { - // Replaces the field name and the view id. - $is_update = TRUE; - $field['id'] = str_replace($old_field, $new_field, $field['id']); - $field['field'] = str_replace($old_field, $new_field, $field['field']); - - // Replace key with save order. - $field_name_update = str_replace($old_field, $new_field, $field_name); - $fields = $display['display_options']['fields']; - $keys = array_keys($fields); - $keys[array_search($field_name, $keys)] = $field_name_update; - $display['display_options']['fields'] = array_combine($keys, $fields); - $display['display_options']['fields'][$field_name_update] = $field; - } - } - } - } - if ($is_update) { - $view->set('display', $displays); - } - return $is_update; - } - - /** - * Checks each display in a view to see if it needs the hyphen fix. - * - * @param \Drupal\views\ViewEntityInterface $view - * The view entity. - * - * @return bool - * TRUE if the view has any displays that needed to be updated. - */ - public function needsRevisionFieldHyphenFix(ViewEntityInterface $view): bool { - return $this->processDisplayHandlers($view, TRUE, function (&$handler, $handler_type) use ($view) { - return $this->processRevisionFieldHyphenFix($view); - }); - } - - /** - * Checks for each view if default_argument_skip_url needs to be removed. - * - * @param \Drupal\views\ViewEntityInterface $view - * The view entity. - * - * @return bool - * TRUE if the view has any arguments that need to have - * default_argument_skip_url removed. - */ - public function needsDefaultArgumentSkipUrlUpdate(ViewEntityInterface $view) { - return $this->processDisplayHandlers($view, TRUE, function (&$handler, $handler_type) { - return $this->processDefaultArgumentSkipUrlUpdate($handler, $handler_type); - }); - } - - /** - * Processes arguments and removes the default_argument_skip_url setting. - * - * @param array $handler - * A display handler. - * @param string $handler_type - * The handler type. - * - * @return bool - * Whether the handler was updated. - */ - public function processDefaultArgumentSkipUrlUpdate(array &$handler, string $handler_type): bool { - if ($handler_type === 'argument' && isset($handler['default_argument_skip_url'])) { - unset($handler['default_argument_skip_url']); - return TRUE; - } - return FALSE; - } - - /** - * Removes user context from all views using term filter configurations. - * - * @param \Drupal\views\ViewEntityInterface $view - * The View to update. - * - * @return bool - * Whether the view was updated. - */ - public function needsTaxonomyTermFilterUpdate(ViewEntityInterface $view): bool { - return $this->processDisplayHandlers($view, TRUE, function (&$handler, $handler_type) use ($view) { - return $this->processTaxonomyTermFilterHandler($handler, $handler_type, $view); - }); - } - - /** - * Processes taxonomy_index_tid type filters. - * - * @param array $handler - * A display handler. - * @param string $handler_type - * The handler type. - * @param \Drupal\views\ViewEntityInterface $view - * The View being updated. - * - * @return bool - * Whether the handler was updated. - */ - protected function processTaxonomyTermFilterHandler(array &$handler, string $handler_type, ViewEntityInterface $view): bool { - $changed = FALSE; - - // Force view resave if using taxonomy id filter. - $plugin_id = $handler['plugin_id'] ?? ''; - if ($handler_type === 'filter' && $plugin_id === 'taxonomy_index_tid') { - - // This cannot be done in View::preSave() due to trusted data. - $executable = $view->getExecutable(); - $displays = $view->get('display'); - foreach ($displays as $display_id => &$display) { - $executable->setDisplay($display_id); - - $cache_metadata = $executable->getDisplay()->calculateCacheMetadata(); - $display['cache_metadata']['contexts'] = $cache_metadata->getCacheContexts(); - // Always include at least the 'languages:' context as there will most - // probably be translatable strings in the view output. - $display['cache_metadata']['contexts'] = Cache::mergeContexts($display['cache_metadata']['contexts'], ['languages:' . LanguageInterface::TYPE_INTERFACE]); - sort($display['cache_metadata']['contexts']); - } - $view->set('display', $displays); - $changed = TRUE; - } - return $changed; - } - - /** - * Checks for each view if pagination_heading_level needs to be added. - * - * @param \Drupal\views\ViewEntityInterface $view - * The view entity. - * - * @return bool - * TRUE if the view has any displays that need to have - * pagination_heading_level added. - */ - public function needsPagerHeadingUpdate(ViewEntityInterface $view): bool { - return $this->processDisplayHandlers($view, FALSE, function (&$handler, $handler_type) { - return $this->processDefaultPagerHeadingUpdate($handler, $handler_type); - }); - } - - /** - * Processes displays and adds pagination_heading_level if necessary. - * - * @param $compound_handler - * A compound display handler. - * @param string $handler_type - * The handler type. - * - * @return bool - * Whether the handler was updated. - */ - public function processDefaultPagerHeadingUpdate(array &$compound_handler, string $handler_type): bool { - $allow_pager_type_update = [ - 'mini', - 'full', - ]; - - if ($handler_type === 'pager' && in_array($compound_handler['type'], $allow_pager_type_update) && !isset($compound_handler['options']['pagination_heading_level'])) { - $compound_handler['options']['pagination_heading_level'] = 'h4'; - return TRUE; - } - return FALSE; - } - - /** - * Checks for entity view display cache tags from rendered entity fields. - * - * @param \Drupal\views\ViewEntityInterface $view - * The View to update. - * - * @return bool - * TRUE if view has rendered_entity fields. - */ - public function needsRenderedEntityFieldUpdate(ViewEntityInterface $view): bool { - return $this->processDisplayHandlers($view, TRUE, function (&$handler, $handler_type) { - return $this->processRenderedEntityFieldHandler($handler, $handler_type); - }); - } - - /** - * Processes rendered_entity type fields. - * - * @param array $handler - * A display handler. - * @param string $handler_type - * The handler type. - * - * @return bool - * Whether the handler was updated. - */ - protected function processRenderedEntityFieldHandler(array &$handler, string $handler_type): bool { - // Force view re-save if using rendered entity field. - $plugin_id = $handler['plugin_id'] ?? ''; - return $handler_type === 'field' && $plugin_id === 'rendered_entity'; - } - } diff --git a/core/modules/views/tests/fixtures/update/views.view.test_entity_field_renderered_entity.yml b/core/modules/views/tests/fixtures/update/views.view.test_entity_field_renderered_entity.yml deleted file mode 100644 index 760de796fec5ed6f2c08435d6d0c810a3f5355d5..0000000000000000000000000000000000000000 --- a/core/modules/views/tests/fixtures/update/views.view.test_entity_field_renderered_entity.yml +++ /dev/null @@ -1,210 +0,0 @@ -langcode: en -status: true -dependencies: - config: - - core.entity_view_mode.node.default - module: - - node -id: test_entity_field_renderered_entity -label: test_entity_field_renderered_entity -module: views -description: '' -tag: '' -base_table: node_field_data -base_field: nid -display: - default: - id: default - display_title: Default - display_plugin: default - position: 0 - display_options: - fields: - rendered_entity: - id: rendered_entity - table: node - field: rendered_entity - relationship: none - group_type: group - admin_label: '' - entity_type: node - plugin_id: rendered_entity - label: '' - exclude: false - alter: - alter_text: false - text: '' - make_link: false - path: '' - absolute: false - external: false - replace_spaces: false - path_case: none - trim_whitespace: false - alt: '' - rel: '' - link_class: '' - prefix: '' - suffix: '' - target: '' - nl2br: false - max_length: 0 - word_boundary: true - ellipsis: true - more_link: false - more_link_text: '' - more_link_path: '' - strip_tags: false - trim: false - preserve_tags: '' - html: false - element_type: '' - element_class: '' - element_label_type: '' - element_label_class: '' - element_label_colon: false - element_wrapper_type: '' - element_wrapper_class: '' - element_default_classes: true - empty: '' - hide_empty: false - empty_zero: false - hide_alter_empty: true - view_mode: default - pager: - type: none - options: - offset: 0 - sorts: - nid: - id: nid - table: node_field_data - field: nid - relationship: none - group_type: group - admin_label: '' - entity_type: node - entity_field: nid - plugin_id: standard - order: ASC - expose: - label: '' - exposed: false - title: - id: title - table: node_field_data - field: title - entity_type: node - entity_field: title - plugin_id: standard - row: - type: fields - defaults: - pager: false - fields: false - sorts: false - rendering_language: '***LANGUAGE_entity_translation***' - display_extenders: { } - cache_metadata: - max-age: -1 - contexts: - - 'languages:language_interface' - - 'user.node_grants:view' - tags: - - 'config:core.entity_view_display.node.article.default' - page_1: - id: page_1 - display_title: Page - display_plugin: page - position: 1 - display_options: - rendering_language: '***LANGUAGE_entity_translation***' - display_extenders: { } - path: test_entity_field_renderered_entity/entity_translation - cache_metadata: - max-age: -1 - contexts: - - 'languages:language_interface' - - 'user.node_grants:view' - tags: - - 'config:core.entity_view_display.node.article.default' - page_2: - id: page_2 - display_title: Page - display_plugin: page - position: 2 - display_options: - rendering_language: '***LANGUAGE_entity_default***' - display_extenders: { } - path: test_entity_field_renderered_entity/entity_default - cache_metadata: - max-age: -1 - contexts: - - 'languages:language_interface' - - 'user.node_grants:view' - tags: - - 'config:core.entity_view_display.node.article.default' - page_3: - id: page_3 - display_title: Page - display_plugin: page - position: 3 - display_options: - rendering_language: '***LANGUAGE_site_default***' - display_extenders: { } - path: test_entity_field_renderered_entity/site_default - cache_metadata: - max-age: -1 - contexts: - - 'languages:language_interface' - - 'user.node_grants:view' - tags: - - 'config:core.entity_view_display.node.article.default' - page_4: - id: page_4 - display_title: Page - display_plugin: page - position: 4 - display_options: - rendering_language: '***LANGUAGE_language_interface***' - display_extenders: { } - path: test_entity_field_renderered_entity/language_interface - cache_metadata: - max-age: -1 - contexts: - - 'languages:language_interface' - - 'user.node_grants:view' - tags: - - 'config:core.entity_view_display.node.article.default' - page_5: - id: page_5 - display_title: Page - display_plugin: page - position: 5 - display_options: - rendering_language: en - display_extenders: { } - path: test_entity_field_renderered_entity/en - cache_metadata: - max-age: -1 - contexts: - - 'languages:language_interface' - - 'user.node_grants:view' - tags: - - 'config:core.entity_view_display.node.article.default' - page_6: - id: page_6 - display_title: Page - display_plugin: page - position: 6 - display_options: - rendering_language: es - display_extenders: { } - path: test_entity_field_renderered_entity/es - cache_metadata: - max-age: -1 - contexts: - - 'languages:language_interface' - - 'user.node_grants:view' - tags: - - 'config:core.entity_view_display.node.article.default' diff --git a/core/modules/views/tests/fixtures/update/views.view.test_responsive_images.yml b/core/modules/views/tests/fixtures/update/views.view.test_responsive_images.yml deleted file mode 100644 index 6537c27184af8f89413d072953fba8740ff48601..0000000000000000000000000000000000000000 --- a/core/modules/views/tests/fixtures/update/views.view.test_responsive_images.yml +++ /dev/null @@ -1,224 +0,0 @@ -uuid: 6a7eb126-7ba9-493f-a209-e3aa0672b8f5 -langcode: en -status: true -dependencies: - config: - - field.storage.entity_test.bar - - responsive_image.styles.responsive_image_style_id - module: - - entity_test - - responsive_image -id: test_responsive_images -label: 'Responsive Images' -module: views -description: '' -tag: '' -base_table: entity_test -base_field: id -display: - default: - display_plugin: default - id: default - display_title: Default - position: 0 - display_options: - access: - type: none - options: { } - cache: - type: tag - options: { } - query: - type: views_query - options: - disable_sql_rewrite: false - distinct: false - replica: false - query_comment: '' - query_tags: { } - exposed_form: - type: basic - options: - submit_button: Apply - reset_button: false - reset_button_label: Reset - exposed_sorts_label: 'Sort by' - expose_sort_order: true - sort_asc_label: Asc - sort_desc_label: Desc - pager: - type: mini - options: - items_per_page: 10 - offset: 0 - id: 0 - total_pages: null - expose: - items_per_page: false - items_per_page_label: 'Items per page' - items_per_page_options: '5, 10, 25, 50' - items_per_page_options_all: false - items_per_page_options_all_label: '- All -' - offset: false - offset_label: Offset - tags: - previous: ‹‹ - next: ›› - style: - type: default - options: - grouping: { } - row_class: '' - default_row_class: true - uses_fields: false - row: - type: fields - options: - inline: { } - separator: '' - hide_empty: false - default_field_elements: true - fields: - name: - table: entity_test - field: name - id: name - entity_type: null - entity_field: name - plugin_id: field - relationship: none - group_type: group - admin_label: '' - label: '' - exclude: false - alter: - alter_text: false - text: '' - make_link: false - path: '' - absolute: false - external: false - replace_spaces: false - path_case: none - trim_whitespace: false - alt: '' - rel: '' - link_class: '' - prefix: '' - suffix: '' - target: '' - nl2br: false - max_length: 0 - word_boundary: true - ellipsis: true - more_link: false - more_link_text: '' - more_link_path: '' - strip_tags: false - trim: false - preserve_tags: '' - html: false - element_type: '' - element_class: '' - element_label_type: '' - element_label_class: '' - element_label_colon: true - element_wrapper_type: '' - element_wrapper_class: '' - element_default_classes: true - empty: '' - hide_empty: false - empty_zero: false - hide_alter_empty: true - click_sort_column: value - type: string - settings: { } - group_column: value - group_columns: { } - group_rows: true - delta_limit: 0 - delta_offset: 0 - delta_reversed: false - delta_first_last: false - multi_type: separator - separator: ', ' - field_api_classes: false - bar: - id: bar - table: entity_test__bar - field: bar - relationship: none - group_type: group - admin_label: '' - label: '' - exclude: false - alter: - alter_text: false - text: '' - make_link: false - path: '' - absolute: false - external: false - replace_spaces: false - path_case: none - trim_whitespace: false - alt: '' - rel: '' - link_class: '' - prefix: '' - suffix: '' - target: '' - nl2br: false - max_length: 0 - word_boundary: true - ellipsis: true - more_link: false - more_link_text: '' - more_link_path: '' - strip_tags: false - trim: false - preserve_tags: '' - html: false - element_type: '' - element_class: '' - element_label_type: '' - element_label_class: '' - element_label_colon: false - element_wrapper_type: '' - element_wrapper_class: '' - element_default_classes: true - empty: '' - hide_empty: false - empty_zero: false - hide_alter_empty: true - click_sort_column: target_id - type: responsive_image - settings: - responsive_image_style: responsive_image_style_id - image_link: '' - group_column: '' - group_columns: { } - group_rows: true - delta_limit: 0 - delta_offset: 0 - delta_reversed: false - delta_first_last: false - multi_type: separator - separator: ', ' - field_api_classes: false - plugin_id: field - filters: { } - sorts: { } - header: { } - footer: { } - empty: { } - relationships: { } - arguments: { } - display_extenders: { } - cache_metadata: - max-age: -1 - contexts: - - entity_test_view_grants - - 'languages:language_content' - - 'languages:language_interface' - - url.query_args diff --git a/core/modules/views/tests/src/Kernel/ViewsConfigUpdaterTest.php b/core/modules/views/tests/src/Kernel/ViewsConfigUpdaterTest.php index 5c0a91d6cfcf06c76e2d2a22f838a72e51decea2..bee833525e88ac6df595a717aaf3b37d901c6bb3 100644 --- a/core/modules/views/tests/src/Kernel/ViewsConfigUpdaterTest.php +++ b/core/modules/views/tests/src/Kernel/ViewsConfigUpdaterTest.php @@ -5,11 +5,6 @@ namespace Drupal\Tests\views\Kernel; use Drupal\Core\Config\FileStorage; -use Drupal\field\Entity\FieldConfig; -use Drupal\field\Entity\FieldStorageConfig; -use Drupal\responsive_image\Entity\ResponsiveImageStyle; -use Drupal\Tests\responsive_image\Functional\ViewsIntegrationTest; -use Drupal\views\ViewsConfigUpdater; /** * @coversDefaultClass \Drupal\views\ViewsConfigUpdater @@ -25,90 +20,9 @@ class ViewsConfigUpdaterTest extends ViewsKernelTestBase { protected static $modules = [ 'views_config_entity_test', 'entity_test', - 'breakpoint', 'field', - 'file', - 'image', - 'responsive_image', - 'responsive_image_test_module', ]; - /** - * @covers ::needsResponsiveImageLazyLoadFieldUpdate - */ - public function testNeedsResponsiveImageLazyLoadFieldUpdate(): void { - $config_updater = $this->container - ->get('class_resolver') - ->getInstanceFromDefinition(ViewsConfigUpdater::class); - assert($config_updater instanceof ViewsConfigUpdater); - - FieldStorageConfig::create([ - 'field_name' => 'user_picture', - 'entity_type' => 'user', - 'type' => 'image', - ])->save(); - FieldConfig::create([ - 'entity_type' => 'user', - 'field_name' => 'user_picture', - 'file_directory' => 'pictures/[date:custom:Y]-[date:custom:m]', - 'bundle' => 'user', - ])->save(); - - // Create a responsive image style. - ResponsiveImageStyle::create([ - 'id' => ViewsIntegrationTest::RESPONSIVE_IMAGE_STYLE_ID, - 'label' => 'Foo', - 'breakpoint_group' => 'responsive_image_test_module', - ]); - // Create an image field to be used with a responsive image formatter. - FieldStorageConfig::create([ - 'type' => 'image', - 'entity_type' => 'entity_test', - 'field_name' => 'bar', - ])->save(); - FieldConfig::create([ - 'entity_type' => 'entity_test', - 'bundle' => 'entity_test', - 'field_name' => 'bar', - ])->save(); - - $test_view = $this->loadTestView('views.view.test_responsive_images'); - $needs_update = $config_updater->needsResponsiveImageLazyLoadFieldUpdate($test_view); - $test_view->save(); - $this->assertTrue($needs_update); - - $default_display = $test_view->getDisplay('default'); - self::assertEquals('eager', $default_display['display_options']['fields']['bar']['settings']['image_loading']['attribute']); - } - - /** - * @covers ::needsRenderedEntityFieldUpdate - */ - public function testNeedsRenderedEntityFieldUpdate(): void { - $config_updater = $this->container - ->get('class_resolver') - ->getInstanceFromDefinition(ViewsConfigUpdater::class); - assert($config_updater instanceof ViewsConfigUpdater); - $test_view = $this->loadTestView('views.view.test_entity_field_renderered_entity'); - $needs_update = $config_updater->needsRenderedEntityFieldUpdate($test_view); - $test_view->save(); - $this->assertTrue($needs_update); - - $displays = [ - 'default', - 'page_1', - 'page_2', - 'page_3', - 'page_4', - 'page_5', - 'page_6', - ]; - foreach ($displays as $display) { - $display = $test_view->getDisplay($display); - self::assertEmpty($display['cache_metadata']['tags']); - } - } - /** * Loads a test view. *