You are here

class OrganigramsBlocks in Organigrams 8

Same name in this branch
  1. 8 src/Plugin/Derivative/OrganigramsBlocks.php \Drupal\organigrams\Plugin\Derivative\OrganigramsBlocks
  2. 8 src/Plugin/Block/OrganigramsBlocks.php \Drupal\organigrams\Plugin\Block\OrganigramsBlocks
Same name and namespace in other branches
  1. 8.2 src/Plugin/Derivative/OrganigramsBlocks.php \Drupal\organigrams\Plugin\Derivative\OrganigramsBlocks

Provides block plugin definitions for organigrams.

Hierarchy

Expanded class hierarchy of OrganigramsBlocks

See also

\Drupal\organigrams\Plugin\Block\NodeBlock

File

src/Plugin/Derivative/OrganigramsBlocks.php, line 15

Namespace

Drupal\organigrams\Plugin\Derivative
View source
class OrganigramsBlocks extends DeriverBase implements ContainerDeriverInterface {

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

  /**
   * Constructs new OrganigramsBlocks.
   *
   * @param \Drupal\Core\Entity\EntityStorageInterface $taxonomy_storage
   *   The taxonomy storage.
   */
  public function __construct(EntityStorageInterface $taxonomy_storage) {
    $this->taxonomyStorage = $taxonomy_storage;
  }

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

  /**
   * {@inheritdoc}
   *
   * Create a block for every organigram.
   */
  public function getDerivativeDefinitions($base_plugin_definition) {

    // Load all vocabularies and iterate through them.
    $taxonomy_vocabularies = $this->taxonomyStorage
      ->loadMultiple();
    foreach ($taxonomy_vocabularies as $vocabulary) {

      // Skip if the vocabulary has no organigrams settings.
      if (empty($vocabulary
        ->getThirdPartySettings('organigrams'))) {
        continue;
      }

      // Create the block.
      $this->derivatives[$vocabulary
        ->id()] = $base_plugin_definition;
      $this->derivatives[$vocabulary
        ->id()]['admin_label'] = t('Organigram block:') . ' ' . $vocabulary
        ->label();
    }
    return $this->derivatives;
  }

}

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
OrganigramsBlocks::$taxonomyStorage protected property The node storage.
OrganigramsBlocks::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
OrganigramsBlocks::getDerivativeDefinitions public function Create a block for every organigram. Overrides DeriverBase::getDerivativeDefinitions
OrganigramsBlocks::__construct public function Constructs new OrganigramsBlocks.