class ViewsConfigUpdater

Same name and namespace in other branches
  1. 11.x core/modules/views/src/ViewsConfigUpdater.php \Drupal\views\ViewsConfigUpdater
  2. 10 core/modules/views/src/ViewsConfigUpdater.php \Drupal\views\ViewsConfigUpdater
  3. 9 core/modules/views/src/ViewsConfigUpdater.php \Drupal\views\ViewsConfigUpdater
  4. 8.9.x core/modules/views/src/ViewsConfigUpdater.php \Drupal\views\ViewsConfigUpdater

Provides a BC layer for modules providing old configurations.

@internal

Hierarchy

Expanded class hierarchy of ViewsConfigUpdater

4 files declare their use of ViewsConfigUpdater
ViewsConfigUpdaterTest.php in core/modules/views/tests/src/Kernel/ViewsConfigUpdaterTest.php
ViewsHooks.php in core/modules/views/src/Hook/ViewsHooks.php
ViewsTestConfigUpdaterHooks.php in core/modules/views/tests/modules/views_test_config_updater/src/Hook/ViewsTestConfigUpdaterHooks.php
views_test_config_updater.post_update.php in core/modules/views/tests/modules/views_test_config_updater/views_test_config_updater.post_update.php

File

core/modules/views/src/ViewsConfigUpdater.php, line 17

Namespace

Drupal\views
View source
class ViewsConfigUpdater {
  
  /**
   * Flag determining whether deprecations should be triggered.
   */
  protected bool $deprecationsEnabled = TRUE;
  
  /**
   * Stores which deprecations were triggered.
   */
  protected array $triggeredDeprecations = [];
  
  /**
   * ViewsConfigUpdater constructor.
   */
  public function __construct(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, protected EntityDisplayRepositoryInterface $entityDisplayRepository) {
  }
  
  /**
   * Sets the deprecations enabling status.
   *
   * @param bool $enabled
   *   Whether deprecations should be 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
   *   The View to update.
   *
   * @return bool
   *   Whether the view was updated.
   */
  public function updateAll(ViewEntityInterface $view) {
    return $this->processDisplayHandlers($view, FALSE, function (&$handler, $handler_type, $key, $display_id) {
      // @todo leaving this here now but new update hooks will need to update.
      return FALSE;
    });
  }
  
  /**
   * Processes all display handlers.
   *
   * @param \Drupal\views\ViewEntityInterface $view
   *   The View to update.
   * @param bool $return_on_changed
   *   Whether processing should stop after a change is detected.
   * @param callable $handler_processor
   *   A callback performing the actual update.
   *
   * @return bool
   *   Whether the view was updated.
   */
  protected function processDisplayHandlers(ViewEntityInterface $view, $return_on_changed, callable $handler_processor) {
    $changed = FALSE;
    $displays = $view->get('display');
    $handler_types = [
      'field' => 'fields',
      'argument' => 'arguments',
      'sort' => 'sorts',
      'relationship' => 'relationships',
      'filter' => 'filters',
      'pager' => 'pager',
    ];
    $compound_display_handlers = [
      'pager',
    ];
    foreach ($displays as $display_id => &$display) {
      foreach ($handler_types as $handler_type => $handler_type_lookup) {
        if (!empty($display['display_options'][$handler_type_lookup])) {
          if (in_array($handler_type_lookup, $compound_display_handlers)) {
            if ($handler_processor($display['display_options'][$handler_type_lookup], $handler_type, NULL, $display_id)) {
              $changed = TRUE;
              if ($return_on_changed) {
                return $changed;
              }
            }
            continue;
          }
          foreach ($display['display_options'][$handler_type_lookup] as $key => &$handler) {
            if (is_array($handler) && $handler_processor($handler, $handler_type, $key, $display_id)) {
              $changed = TRUE;
              if ($return_on_changed) {
                return $changed;
              }
            }
          }
        }
      }
    }
    if ($changed) {
      $view->set('display', $displays);
    }
    return $changed;
  }

}

Members

Title Sort descending Modifiers Object type Summary
ViewsConfigUpdater::$deprecationsEnabled protected property Flag determining whether deprecations should be triggered.
ViewsConfigUpdater::$triggeredDeprecations protected property Stores which deprecations were triggered.
ViewsConfigUpdater::areDeprecationsEnabled public function Whether deprecations are enabled.
ViewsConfigUpdater::processDisplayHandlers protected function Processes all display handlers.
ViewsConfigUpdater::setDeprecationsEnabled public function Sets the deprecations enabling status.
ViewsConfigUpdater::updateAll public function Performs all required updates.
ViewsConfigUpdater::__construct public function ViewsConfigUpdater constructor.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.