ViewUIConverter.php in Zircon Profile 8
File
core/modules/views_ui/src/ParamConverter/ViewUIConverter.php
View source
<?php
namespace Drupal\views_ui\ParamConverter;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\ParamConverter\EntityConverter;
use Symfony\Component\Routing\Route;
use Drupal\Core\ParamConverter\ParamConverterInterface;
use Drupal\user\SharedTempStoreFactory;
use Drupal\views_ui\ViewUI;
class ViewUIConverter extends EntityConverter implements ParamConverterInterface {
protected $tempStoreFactory;
public function __construct(EntityManagerInterface $entity_manager, SharedTempStoreFactory $temp_store_factory) {
parent::__construct($entity_manager);
$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->lock = $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. |