You are here

class EntityBrowserBlockDeriver in Entity Browser Block 8

Retrieves block plugin definitions for all entity browsers.

Hierarchy

Expanded class hierarchy of EntityBrowserBlockDeriver

File

src/Plugin/Derivative/EntityBrowserBlockDeriver.php, line 13

Namespace

Drupal\entity_browser_block\Plugin\Derivative
View source
class EntityBrowserBlockDeriver extends DeriverBase implements ContainerDeriverInterface {

  /**
   * The browser storage.
   *
   * @var \Drupal\Core\Entity\EntityStorageInterface
   */
  protected $browserStorage;

  /**
   * Constructs a EntityBrowserBlockDeriver object.
   *
   * @param \Drupal\Core\Entity\EntityStorageInterface $browser_storage
   *   The browser storage.
   */
  public function __construct(EntityStorageInterface $browser_storage) {
    $this->browserStorage = $browser_storage;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, $base_plugin_id) {
    $entity_manager = $container
      ->get('entity_type.manager');
    return new static($entity_manager
      ->getStorage('entity_browser'));
  }

  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($base_plugin_definition) {

    /** @var \Drupal\entity_browser\EntityBrowserInterface[] $browsers */
    $browsers = $this->browserStorage
      ->loadMultiple();

    // Reset the discovered definitions.
    $this->derivatives = [];
    foreach ($browsers as $browser) {
      $this->derivatives[$browser
        ->id()] = $base_plugin_definition;
      $this->derivatives[$browser
        ->id()]['admin_label'] = $browser
        ->label();
      $this->derivatives[$browser
        ->id()]['config_dependencies']['config'] = [
        $browser
          ->getConfigDependencyName(),
      ];
    }
    return parent::getDerivativeDefinitions($base_plugin_definition);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DeriverBase::$derivatives protected property List of derivative definitions. 1
DeriverBase::getDerivativeDefinition public function Gets the definition of a derivative plugin. Overrides DeriverInterface::getDerivativeDefinition
EntityBrowserBlockDeriver::$browserStorage protected property The browser storage.
EntityBrowserBlockDeriver::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
EntityBrowserBlockDeriver::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions
EntityBrowserBlockDeriver::__construct public function Constructs a EntityBrowserBlockDeriver object.