Verified Commit fecffbff authored by quietone's avatar quietone
Browse files

Issue #3442162 by catch, smustgrave: Remove redundant...

Issue #3442162 by catch, smustgrave: Remove redundant hook_ENTITY_TYPE_presave() and ViewsConfigUpdater methods
parent f68f9f78
Loading
Loading
Loading
Loading
Loading
+0 −38
Changes for core/modules/datetime_range/datetime_range.module: 0 added lines, 38 removed lines.
Original line number Diff line number Diff line
@@ -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);
    }
  }
}
+0 −11
Changes for core/modules/media/media.module: 0 added lines, 11 removed lines.
Original line number Diff line number Diff line
@@ -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().
 */
+0 −72
Changes for core/modules/media/src/MediaConfigUpdater.php: 0 added lines, 72 removed lines.
Original line number Diff line number Diff line
<?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;
  }

}
+0 −15
Changes for core/modules/node/node.module: 0 added lines, 15 removed lines.
Original line number Diff line number Diff line
@@ -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);
  }
}
+0 −11
Changes for core/modules/responsive_image/responsive_image.module: 0 added lines, 11 removed lines.
Original line number Diff line number Diff line
@@ -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);
}
Loading