You are here

class TagPluginDeriver in Extensible BBCode 4.0.x

Same name and namespace in other branches
  1. 8.3 src/Plugin/Derivative/TagPluginDeriver.php \Drupal\xbbcode\Plugin\Derivative\TagPluginDeriver

Provide a tag plugin for each XBBCodeCustom entity.

Hierarchy

Expanded class hierarchy of TagPluginDeriver

File

src/Plugin/Derivative/TagPluginDeriver.php, line 14

Namespace

Drupal\xbbcode\Plugin\Derivative
View source
class TagPluginDeriver extends DeriverBase implements ContainerDeriverInterface {

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

  /**
   * Constructs a Deriver.
   *
   * @param \Drupal\Core\Entity\EntityStorageInterface $storage
   *   The entity storage.
   */
  public function __construct(EntityStorageInterface $storage) {
    $this->storage = $storage;
  }

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

  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($base_plugin_definition) : array {
    $xbbcode_tags = $this->storage
      ->loadMultiple();
    foreach ($xbbcode_tags as $id => $tag) {

      /** @var \Drupal\xbbcode\Entity\TagInterface $tag */
      $this->derivatives[$id] = [
        'id' => 'xbbcode_tag' . TagPluginBase::DERIVATIVE_SEPARATOR . $id,
        'label' => $tag
          ->label(),
        'description' => $tag
          ->getDescription(),
        'sample' => $tag
          ->getSample(),
        'name' => $tag
          ->getName(),
      ] + $base_plugin_definition;
    }
    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
TagPluginDeriver::$storage protected property Entity storage.
TagPluginDeriver::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
TagPluginDeriver::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions
TagPluginDeriver::__construct public function Constructs a Deriver.