You are here

class TagBlock in Doubleclick for Publishers (DFP) 8

Same name in this branch
  1. 8 src/Plugin/Derivative/TagBlock.php \Drupal\dfp\Plugin\Derivative\TagBlock
  2. 8 src/Plugin/Block/TagBlock.php \Drupal\dfp\Plugin\Block\TagBlock

Retrieves block plugin definitions for all available DFP Ad tags.

Hierarchy

Expanded class hierarchy of TagBlock

File

src/Plugin/Derivative/TagBlock.php, line 19
Contains \Drupal\dfp\Plugin\Derivative\TagBlock.

Namespace

Drupal\dfp\Plugin\Derivative
View source
class TagBlock extends DeriverBase implements ContainerDeriverInterface {
  use StringTranslationTrait;

  /**
   * The DFP tag storage.
   *
   * @var \Drupal\Core\Entity\EntityStorageInterface
   */
  protected $tagStorage;

  /**
   * Constructs a TagBlock object.
   *
   * @param \Drupal\Core\Entity\EntityStorageInterface $tag_storage
   *   The DFP tag storage.
   */
  public function __construct(EntityStorageInterface $tag_storage) {
    $this->tagStorage = $tag_storage;
  }

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

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

    /** @var \Drupal\dfp\Entity\TagInterface[] $tags */
    $tags = $this->tagStorage
      ->loadMultiple();
    foreach ($tags as $tag) {
      if ($tag
        ->hasBlock()) {
        $this->derivatives[$tag
          ->uuid()] = $base_plugin_definition;
        $this->derivatives[$tag
          ->uuid()]['admin_label'] = $this
          ->t('DFP tag: @slotname', [
          '@slotname' => $tag
            ->slot(),
        ]);
        $this->derivatives[$tag
          ->uuid()]['config_dependencies']['config'] = [
          $tag
            ->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
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.
TagBlock::$tagStorage protected property The DFP tag storage.
TagBlock::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
TagBlock::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions
TagBlock::__construct public function Constructs a TagBlock object.