function ViewsConfigUpdater::processMultivalueBaseFieldHandler

Same name in other branches
  1. 8.9.x core/modules/views/src/ViewsConfigUpdater.php \Drupal\views\ViewsConfigUpdater::processMultivalueBaseFieldHandler()

Processes handlers affected by the multivalue base field update.

Parameters

array $handler: A display handler.

string $handler_type: The handler type.

string $key: The handler key.

string $display_id: The handler display ID.

\Drupal\views\ViewEntityInterface $view: The view being updated.

Return value

bool Whether the handler was updated.

2 calls to ViewsConfigUpdater::processMultivalueBaseFieldHandler()
ViewsConfigUpdater::needsMultivalueBaseFieldUpdate in core/modules/views/src/ViewsConfigUpdater.php
Update field names for multi-value base fields.
ViewsConfigUpdater::updateAll in core/modules/views/src/ViewsConfigUpdater.php
Performs all required updates.

File

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

Class

ViewsConfigUpdater
Provides a BC layer for modules providing old configurations.

Namespace

Drupal\views

Code

protected function processMultivalueBaseFieldHandler(array &$handler, $handler_type, $key, $display_id, ViewEntityInterface $view) {
    $changed = FALSE;
    // If there are no multivalue base fields we have nothing to do.
    $table_info = $this->getMultivalueBaseFieldUpdateTableInfo();
    if (!$table_info) {
        return $changed;
    }
    // Only if the wrong field name is set do we process the field. It
    // could already be using the correct field. Like "user__roles" vs
    // "roles_target_id".
    if (isset($handler['table']) && isset($table_info[$handler['table']]) && isset($table_info[$handler['table']][$handler['field']])) {
        $changed = TRUE;
        $original_field_name = $handler['field'];
        $handler['field'] = $table_info[$handler['table']][$original_field_name];
        $handler['plugin_id'] = $this->viewsData
            ->get($handler['table'])[$table_info[$handler['table']][$original_field_name]][$handler_type]['id'];
        // Retrieve type data information about the handler to clean it up
        // reliably. We need to manually create a typed view rather than
        // instantiating the current one, as the schema will be affected by the
        // updated values.
        $id = 'views.view.' . $view->id();
        $path_to_handler = "display.{$display_id}.display_options.{$handler_type}s.{$key}";
        $view_config = $view->toArray();
        $keys = explode('.', $path_to_handler);
        NestedArray::setValue($view_config, $keys, $handler);
        
        /** @var \Drupal\Core\Config\Schema\TypedConfigInterface $typed_view */
        $typed_view = $this->typedConfigManager
            ->createFromNameAndData($id, $view_config);
        
        /** @var \Drupal\Core\Config\Schema\ArrayElement $typed_handler */
        $typed_handler = $typed_view->get($path_to_handler);
        // Filter values we want to convert from a string to an array.
        if ($handler_type === 'filter' && $typed_handler->get('value') instanceof ArrayElement && is_string($handler['value'])) {
            // An empty string cast to an array is an array with one element.
            if ($handler['value'] === '') {
                $handler['value'] = [];
            }
            else {
                $handler['value'] = (array) $handler['value'];
            }
            $handler['operator'] = $this->mapOperatorFromSingleToMultiple($handler['operator']);
        }
        // For all the other fields we try to determine the fields using config
        // schema and remove everything not being defined in the new handler.
        foreach (array_keys($handler) as $handler_key) {
            if (!isset($typed_handler->getDataDefinition()['mapping'][$handler_key])) {
                unset($handler[$handler_key]);
            }
        }
    }
    $deprecations_triggered =& $this->triggeredDeprecations['2900684'][$view->id()];
    if ($this->deprecationsEnabled && $changed && !$deprecations_triggered) {
        $deprecations_triggered = TRUE;
        @trigger_error(sprintf('The multivalue base field update for the "%s" view is deprecated in drupal:9.0.0 and is removed from drupal:10.0.0. Module-provided Views configuration should be updated to accommodate the changes described at https://www.drupal.org/node/2900684.', $view->id()), E_USER_DEPRECATED);
    }
    return $changed;
}

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