diff options
Diffstat (limited to 'core/modules/views/src/ViewsConfigUpdater.php')
-rw-r--r-- | core/modules/views/src/ViewsConfigUpdater.php | 101 |
1 files changed, 20 insertions, 81 deletions
diff --git a/core/modules/views/src/ViewsConfigUpdater.php b/core/modules/views/src/ViewsConfigUpdater.php index 9c5d38e10ac..c6a4fbc62d0 100644 --- a/core/modules/views/src/ViewsConfigUpdater.php +++ b/core/modules/views/src/ViewsConfigUpdater.php @@ -4,106 +4,38 @@ namespace Drupal\views; use Drupal\Component\Plugin\PluginManagerInterface; use Drupal\Core\Config\TypedConfigManagerInterface; -use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Drupal\Core\Entity\EntityFieldManagerInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; -use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\DependencyInjection\Attribute\Autowire; /** * Provides a BC layer for modules providing old configurations. * * @internal */ -class ViewsConfigUpdater implements ContainerInjectionInterface { - - /** - * The entity type manager. - * - * @var \Drupal\Core\Entity\EntityTypeManagerInterface - */ - protected $entityTypeManager; - - /** - * The entity field manager. - * - * @var \Drupal\Core\Entity\EntityFieldManagerInterface - */ - protected $entityFieldManager; - - /** - * The typed config manager. - * - * @var \Drupal\Core\Config\TypedConfigManagerInterface - */ - protected $typedConfigManager; - - /** - * The views data service. - * - * @var \Drupal\views\ViewsData - */ - protected $viewsData; - - /** - * The formatter plugin manager service. - * - * @var \Drupal\Component\Plugin\PluginManagerInterface - */ - protected $formatterPluginManager; +class ViewsConfigUpdater { /** * Flag determining whether deprecations should be triggered. - * - * @var bool */ - protected $deprecationsEnabled = TRUE; + protected bool $deprecationsEnabled = TRUE; /** * Stores which deprecations were triggered. - * - * @var bool */ - protected $triggeredDeprecations = []; + protected array $triggeredDeprecations = []; /** * ViewsConfigUpdater constructor. - * - * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager - * The entity type manager. - * @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager - * The entity field manager. - * @param \Drupal\Core\Config\TypedConfigManagerInterface $typed_config_manager - * The typed config manager. - * @param \Drupal\views\ViewsData $views_data - * The views data service. - * @param \Drupal\Component\Plugin\PluginManagerInterface $formatter_plugin_manager - * The formatter plugin manager service. */ public function __construct( - EntityTypeManagerInterface $entity_type_manager, - EntityFieldManagerInterface $entity_field_manager, - TypedConfigManagerInterface $typed_config_manager, - ViewsData $views_data, - PluginManagerInterface $formatter_plugin_manager, + private readonly EntityTypeManagerInterface $entityTypeManager, + private readonly EntityFieldManagerInterface $entityFieldManager, + private readonly TypedConfigManagerInterface $typedConfigManager, + private readonly ViewsData $viewsData, + #[Autowire(service: 'plugin.manager.field.formatter')] + private readonly PluginManagerInterface $formatterPluginManager, ) { - $this->entityTypeManager = $entity_type_manager; - $this->entityFieldManager = $entity_field_manager; - $this->typedConfigManager = $typed_config_manager; - $this->viewsData = $views_data; - $this->formatterPluginManager = $formatter_plugin_manager; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container) { - return new static( - $container->get('entity_type.manager'), - $container->get('entity_field.manager'), - $container->get('config.typed'), - $container->get('views.views_data'), - $container->get('plugin.manager.field.formatter') - ); } /** @@ -112,11 +44,18 @@ class ViewsConfigUpdater implements ContainerInjectionInterface { * @param bool $enabled * Whether deprecations should be enabled. */ - public function setDeprecationsEnabled($enabled) { + public function setDeprecationsEnabled(bool $enabled): void { $this->deprecationsEnabled = $enabled; } /** + * Whether deprecations are enabled. + */ + public function areDeprecationsEnabled(): bool { + return $this->deprecationsEnabled; + } + + /** * Performs all required updates. * * @param \Drupal\views\ViewEntityInterface $view @@ -259,7 +198,7 @@ class ViewsConfigUpdater implements ContainerInjectionInterface { } $deprecations_triggered = &$this->triggeredDeprecations['2640994'][$view->id()]; - if ($this->deprecationsEnabled && $changed && !$deprecations_triggered) { + if ($this->areDeprecationsEnabled() && $changed && !$deprecations_triggered) { $deprecations_triggered = TRUE; @trigger_error(sprintf('The update to convert "numeric" arguments to "entity_target_id" for entity reference fields for view "%s" is deprecated in drupal:10.3.0 and is removed from drupal:12.0.0. Profile, module and theme provided configuration should be updated. See https://www.drupal.org/node/3441945', $view->id()), E_USER_DEPRECATED); } @@ -351,7 +290,7 @@ class ViewsConfigUpdater implements ContainerInjectionInterface { } $deprecations_triggered = &$this->triggeredDeprecations['table_css_class'][$view->id()]; - if ($this->deprecationsEnabled && $changed && !$deprecations_triggered) { + if ($this->areDeprecationsEnabled() && $changed && !$deprecations_triggered) { $deprecations_triggered = TRUE; @trigger_error(sprintf('The update to add a default table CSS class for view "%s" is deprecated in drupal:11.2.0 and is removed from drupal:12.0.0. Profile, module and theme provided configuration should be updated. See https://www.drupal.org/node/3499943', $view->id()), E_USER_DEPRECATED); } |