Drupal 8.0.0 beta 12. More info: https://www.drupal.org/node/2514176
This commit is contained in:
commit
9921556621
13277 changed files with 1459781 additions and 0 deletions
93
core/modules/views_ui/src/ParamConverter/ViewUIConverter.php
Normal file
93
core/modules/views_ui/src/ParamConverter/ViewUIConverter.php
Normal file
|
@ -0,0 +1,93 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\views_ui\ParamConverter\ViewUIConverter.
|
||||
*/
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* Provides upcasting for a view entity to be used in the Views UI.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* pattern: '/some/{view}/and/{bar}'
|
||||
* options:
|
||||
* parameters:
|
||||
* view:
|
||||
* type: 'entity:view'
|
||||
* tempstore: TRUE
|
||||
*
|
||||
* The value for {view} will be converted to a view entity prepared for the
|
||||
* Views UI and loaded from the views temp store, but it will not touch the
|
||||
* value for {bar}.
|
||||
*/
|
||||
class ViewUIConverter extends EntityConverter implements ParamConverterInterface {
|
||||
|
||||
/**
|
||||
* Stores the tempstore factory.
|
||||
*
|
||||
* @var \Drupal\user\SharedTempStoreFactory
|
||||
*/
|
||||
protected $tempStoreFactory;
|
||||
|
||||
/**
|
||||
* Constructs a new ViewUIConverter.
|
||||
*
|
||||
* @param \Drupal\user\SharedTempStoreFactory $temp_store_factory
|
||||
* The factory for the temp store object.
|
||||
*/
|
||||
public function __construct(EntityManagerInterface $entity_manager, SharedTempStoreFactory $temp_store_factory) {
|
||||
parent::__construct($entity_manager);
|
||||
|
||||
$this->tempStoreFactory = $temp_store_factory;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
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->lock = $store->getMetadata($value);
|
||||
}
|
||||
// Otherwise, decorate the existing view for use in the UI.
|
||||
else {
|
||||
$view = new ViewUI($entity);
|
||||
}
|
||||
|
||||
return $view;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function applies($definition, $name, Route $route) {
|
||||
if (parent::applies($definition, $name, $route)) {
|
||||
return !empty($definition['tempstore']) && $definition['type'] === 'entity:view';
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
}
|
Reference in a new issue