ViewUIConverter.php in Drupal 9
File
core/modules/views_ui/src/ParamConverter/ViewUIConverter.php
View source
<?php
namespace Drupal\views_ui\ParamConverter;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\EntityRepositoryInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\ParamConverter\AdminPathConfigEntityConverter;
use Drupal\Core\ParamConverter\ParamConverterInterface;
use Drupal\Core\Routing\AdminContext;
use Drupal\Core\TempStore\SharedTempStoreFactory;
use Drupal\views_ui\ViewUI;
use Symfony\Component\Routing\Route;
class ViewUIConverter extends AdminPathConfigEntityConverter implements ParamConverterInterface {
protected $tempStoreFactory;
public function __construct(EntityTypeManagerInterface $entity_type_manager, SharedTempStoreFactory $temp_store_factory, ConfigFactoryInterface $config_factory, AdminContext $admin_context, EntityRepositoryInterface $entity_repository) {
parent::__construct($entity_type_manager, $config_factory, $admin_context, $entity_repository);
$this->tempStoreFactory = $temp_store_factory;
}
public function convert($value, $definition, $name, array $defaults) {
if (!($entity = parent::convert($value, $definition, $name, $defaults))) {
return;
}
$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;
}
public function applies($definition, $name, Route $route) {
if (parent::applies($definition, $name, $route)) {
return !empty($definition['tempstore']) && $definition['type'] === 'entity:view';
}
return FALSE;
}
}
Classes
Name |
Description |
ViewUIConverter |
Provides upcasting for a view entity to be used in the Views UI. |