You are here

abstract class DisplayBase in Entity Browser 8

Same name and namespace in other branches
  1. 8.2 src/DisplayBase.php \Drupal\entity_browser\DisplayBase

Base implementation for display plugins.

Hierarchy

Expanded class hierarchy of DisplayBase

3 files declare their use of DisplayBase
IFrame.php in src/Plugin/EntityBrowser/Display/IFrame.php
Modal.php in src/Plugin/EntityBrowser/Display/Modal.php
Standalone.php in src/Plugin/EntityBrowser/Display/Standalone.php

File

src/DisplayBase.php, line 19

Namespace

Drupal\entity_browser
View source
abstract class DisplayBase extends PluginBase implements DisplayInterface, ContainerFactoryPluginInterface {
  use PluginConfigurationFormTrait;

  /**
   * Plugin label.
   *
   * @var string
   */
  protected $label;

  /**
   * Selected entities.
   *
   * @var \Drupal\Core\Entity\EntityInterface[]
   */
  protected $entities = [];

  /**
   * Event dispatcher service.
   *
   * @var \Symfony\Component\EventDispatcher\EventDispatcherInterface
   */
  protected $eventDispatcher;

  /**
   * UUID generator interface.
   *
   * @var \Drupal\Component\Uuid\UuidInterface
   */
  protected $uuidGenerator;

  /**
   * Instance UUID string.
   *
   * @var string
   */
  protected $uuid = NULL;

  /**
   * The selection storage.
   *
   * @var \Drupal\Core\KeyValueStore\KeyValueStoreExpirableInterface
   */
  protected $selectionStorage;

  /**
   * Constructs display plugin.
   *
   * @param array $configuration
   *   A configuration array containing information about the plugin instance.
   * @param string $plugin_id
   *   The plugin_id for the plugin instance.
   * @param mixed $plugin_definition
   *   The plugin implementation definition.
   * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher
   *   Event dispatcher service.
   * @param \Drupal\Component\Uuid\UuidInterface $uuid_generator
   *   UUID generator interface.
   * @param \Drupal\Core\KeyValueStore\KeyValueStoreExpirableInterface $selection_storage
   *   The selection storage.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, EventDispatcherInterface $event_dispatcher, UuidInterface $uuid_generator, KeyValueStoreExpirableInterface $selection_storage) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this
      ->setConfiguration($configuration);
    $this->eventDispatcher = $event_dispatcher;
    $this->uuidGenerator = $uuid_generator;
    $this->selectionStorage = $selection_storage;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static($configuration, $plugin_id, $plugin_definition, $container
      ->get('event_dispatcher'), $container
      ->get('uuid'), $container
      ->get('entity_browser.selection_storage'));
  }

  /**
   * {@inheritdoc}
   */
  public function defaultConfiguration() {
    return [];
  }

  /**
   * {@inheritdoc}
   */
  public function getConfiguration() {
    return array_diff_key($this->configuration, [
      'entity_browser_id' => 0,
    ]);
  }

  /**
   * {@inheritdoc}
   */
  public function setConfiguration(array $configuration) {
    $this->configuration = NestedArray::mergeDeep($this
      ->defaultConfiguration(), $configuration);
  }

  /**
   * {@inheritdoc}
   */
  public function calculateDependencies() {
    return [];
  }

  /**
   * {@inheritdoc}
   */
  public function label() {
    return $this->label;
  }

  /**
   * {@inheritdoc}
   */
  public function getUuid() {
    if (empty($this->uuid)) {
      $this->uuid = $this->uuidGenerator
        ->generate();
    }
    return $this->uuid;
  }

  /**
   * {@inheritdoc}
   */
  public function setUuid($uuid) {
    $this->uuid = $uuid;
  }

  /**
   * {@inheritdoc}
   */
  public function displayEntityBrowser(array $element, FormStateInterface $form_state, array &$complete_form, array $persistent_data = []) {

    // Store persistent data so that after being rendered widgets can still
    // have access to contextual information.
    $this->selectionStorage
      ->setWithExpire($this
      ->getUuid(), $persistent_data, Settings::get('entity_browser_expire', 21600));
  }

  /**
   * {@inheritdoc}
   */
  public function selectionCompleted(array $entities) {
    $this->entities = $entities;
    $this->eventDispatcher
      ->addListener(KernelEvents::RESPONSE, [
      $this,
      'propagateSelection',
    ]);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
DisplayBase::$entities protected property Selected entities.
DisplayBase::$eventDispatcher protected property Event dispatcher service.
DisplayBase::$label protected property Plugin label.
DisplayBase::$selectionStorage protected property The selection storage.
DisplayBase::$uuid protected property Instance UUID string.
DisplayBase::$uuidGenerator protected property UUID generator interface.
DisplayBase::calculateDependencies public function Calculates dependencies for the configured plugin. Overrides DependentPluginInterface::calculateDependencies
DisplayBase::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create 1
DisplayBase::defaultConfiguration public function Gets default configuration for this plugin. Overrides ConfigurableInterface::defaultConfiguration 2
DisplayBase::displayEntityBrowser public function Displays entity browser. Overrides DisplayInterface::displayEntityBrowser 2
DisplayBase::getConfiguration public function Gets this plugin's configuration. Overrides ConfigurableInterface::getConfiguration
DisplayBase::getUuid public function Gets the uuid for this display. Overrides DisplayInterface::getUuid
DisplayBase::label public function Returns the display label. Overrides DisplayInterface::label
DisplayBase::selectionCompleted public function Indicates completed selection. Overrides DisplayInterface::selectionCompleted 1
DisplayBase::setConfiguration public function Sets the configuration for this plugin instance. Overrides ConfigurableInterface::setConfiguration
DisplayBase::setUuid public function Sets the uuid for this display. Overrides DisplayInterface::setUuid
DisplayBase::__construct public function Constructs display plugin. Overrides PluginBase::__construct 1
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
PluginConfigurationFormTrait::buildConfigurationForm public function Implements PluginFormInterface::buildConfigurationForm(). 5
PluginConfigurationFormTrait::submitConfigurationForm public function Implements PluginFormInterface::submitConfigurationForm(). 3
PluginConfigurationFormTrait::validateConfigurationForm public function Implements PluginFormInterface::validateConfigurationForm(). 2
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.