You are here

class DashboardBlock in Dashboards with Layout Builder 8

Same name in this branch
  1. 8 src/Plugin/Derivative/DashboardBlock.php \Drupal\dashboards\Plugin\Derivative\DashboardBlock
  2. 8 src/Plugin/Block/DashboardBlock.php \Drupal\dashboards\Plugin\Block\DashboardBlock
Same name and namespace in other branches
  1. 2.0.x src/Plugin/Derivative/DashboardBlock.php \Drupal\dashboards\Plugin\Derivative\DashboardBlock

Provides block plugin definitions for dashboard blocks.

Hierarchy

Expanded class hierarchy of DashboardBlock

File

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

Namespace

Drupal\dashboards\Plugin\Derivative
View source
class DashboardBlock extends DeriverBase implements ContainerDeriverInterface {
  use StringTranslationTrait;

  /**
   * Plugin manager.
   *
   * @var \Drupal\Component\Plugin\PluginManagerInterface
   */
  protected $manager;

  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($base_plugin_definition) {
    $definitions = $this->manager
      ->getDefinitions();
    foreach ($definitions as $id => $definition) {
      $this->derivatives['dashboard:' . $id] = $base_plugin_definition;
      $this->derivatives['dashboard:' . $id]['admin_label'] = $this
        ->t('@display_name', [
        '@display_name' => $definition['label'],
      ]);
      $this->derivatives['dashboard:' . $id]['category'] = $this
        ->t('@category', [
        '@category' => $definition['category'],
      ]);
    }
    return $this->derivatives;
  }

  /**
   * Constructs new DashboardBlock.
   *
   * @param \Drupal\Component\Plugin\PluginManagerInterface $plugin_manager
   *   The entity type manager.
   */
  public function __construct(PluginManagerInterface $plugin_manager) {
    $this->manager = $plugin_manager;
  }

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

}

Members

Namesort descending Modifiers Type Description Overrides
DashboardBlock::$manager protected property Plugin manager.
DashboardBlock::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
DashboardBlock::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions
DashboardBlock::__construct public function Constructs new DashboardBlock.
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.