You are here

public function ViewUIConverter::convert in Drupal 9

Same name in this branch
  1. 9 core/modules/views_ui/src/ParamConverter/ViewUIConverter.php \Drupal\views_ui\ParamConverter\ViewUIConverter::convert()
  2. 9 core/modules/views_ui/src/ProxyClass/ParamConverter/ViewUIConverter.php \Drupal\views_ui\ProxyClass\ParamConverter\ViewUIConverter::convert()
Same name and namespace in other branches
  1. 8 core/modules/views_ui/src/ParamConverter/ViewUIConverter.php \Drupal\views_ui\ParamConverter\ViewUIConverter::convert()
  2. 10 core/modules/views_ui/src/ParamConverter/ViewUIConverter.php \Drupal\views_ui\ParamConverter\ViewUIConverter::convert()

Converts path variables to their corresponding objects.

Parameters

mixed $value: The raw value.

mixed $definition: The parameter definition provided in the route options.

string $name: The name of the parameter.

array $defaults: The route defaults array.

Return value

mixed|null The converted parameter value.

Overrides AdminPathConfigEntityConverter::convert

File

core/modules/views_ui/src/ParamConverter/ViewUIConverter.php, line 63

Class

ViewUIConverter
Provides upcasting for a view entity to be used in the Views UI.

Namespace

Drupal\views_ui\ParamConverter

Code

public function convert($value, $definition, $name, array $defaults) {
  if (!($entity = parent::convert($value, $definition, $name, $defaults))) {
    return;
  }

  // Get the temp store for this variable if it needs one. Attempt to load the
  // view from the temp store, synchronize its status with the existing view,
  // and store the lock metadata.
  $store = $this->tempStoreFactory
    ->get('views');
  if ($view = $store
    ->get($value)) {
    if ($entity
      ->status()) {
      $view
        ->enable();
    }
    else {
      $view
        ->disable();
    }
    $view
      ->setLock($store
      ->getMetadata($value));
  }
  else {
    $view = new ViewUI($entity);
  }
  return $view;
}