You are here

class ViewUIConverter in Drupal 8

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

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}.

Hierarchy

Expanded class hierarchy of ViewUIConverter

1 string reference to 'ViewUIConverter'
views_ui.services.yml in core/modules/views_ui/views_ui.services.yml
core/modules/views_ui/views_ui.services.yml
1 service uses ViewUIConverter
paramconverter.views_ui in core/modules/views_ui/views_ui.services.yml
Drupal\views_ui\ParamConverter\ViewUIConverter

File

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

Namespace

Drupal\views_ui\ParamConverter
View source
class ViewUIConverter extends AdminPathConfigEntityConverter implements ParamConverterInterface {

  /**
   * Stores the tempstore factory.
   *
   * @var \Drupal\Core\TempStore\SharedTempStoreFactory
   */
  protected $tempStoreFactory;

  /**
   * Constructs a new ViewUIConverter.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager.
   * @param \Drupal\Core\TempStore\SharedTempStoreFactory $temp_store_factory
   *   The factory for the temp store object.
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   The config factory.
   * @param \Drupal\Core\Routing\AdminContext $admin_context
   *   The route admin context service.
   * @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository
   *   The entity repository.
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager, SharedTempStoreFactory $temp_store_factory, ConfigFactoryInterface $config_factory = NULL, AdminContext $admin_context = NULL, $entity_repository = NULL) {

    // The config factory and admin context are new arguments due to changing
    // the parent. Avoid an error on updated sites by falling back to getting
    // them from the container.
    // @todo Remove in 8.2.x in https://www.drupal.org/node/2674328.
    if (!$config_factory) {
      $config_factory = \Drupal::configFactory();
    }
    if (!$admin_context) {
      $admin_context = \Drupal::service('router.admin_context');
    }
    parent::__construct($entity_type_manager, $config_factory, $admin_context, $entity_repository);
    $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
        ->setLock($store
        ->getMetadata($value));
    }
    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;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AdminPathConfigEntityConverter::$adminContext protected property The route admin context to determine whether a route is an admin one.
AdminPathConfigEntityConverter::$configFactory protected property The config factory.
DeprecatedServicePropertyTrait::__get public function Allows to access deprecated/removed properties.
DynamicEntityTypeParamConverterTrait::getEntityTypeFromDefaults protected function Determines the entity type ID given a route definition and route defaults.
EntityConverter::$deprecatedProperties protected property
EntityConverter::$entityRepository protected property Entity repository.
EntityConverter::$entityTypeManager protected property Entity type manager which performs the upcasting in the end.
EntityConverter::getLatestTranslationAffectedRevision Deprecated protected function Returns the latest revision translation of the specified entity.
EntityConverter::languageManager protected function Returns a language manager instance.
EntityConverter::loadRevision Deprecated protected function Loads the specified entity revision.
ViewUIConverter::$tempStoreFactory protected property Stores the tempstore factory.
ViewUIConverter::applies public function Determines if the converter applies to a specific route and variable. Overrides AdminPathConfigEntityConverter::applies
ViewUIConverter::convert public function Converts path variables to their corresponding objects. Overrides AdminPathConfigEntityConverter::convert
ViewUIConverter::__construct public function Constructs a new ViewUIConverter. Overrides AdminPathConfigEntityConverter::__construct