You are here

class DraggableBlockDeriver in Draggable dashboard 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/Block/DraggableBlockDeriver.php \Drupal\draggable_dashboard\Plugin\Block\DraggableBlockDeriver

This deriver creates a block for every dashboard that has been created.

Hierarchy

Expanded class hierarchy of DraggableBlockDeriver

File

src/Plugin/Block/DraggableBlockDeriver.php, line 14

Namespace

Drupal\draggable_dashboard\Plugin\Block
View source
class DraggableBlockDeriver extends DeriverBase implements ContainerDeriverInterface {

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, $base_plugin_id) {
    return new static();
  }

  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($base_plugin_definition) {
    $base_plugin_id = $base_plugin_definition['id'];
    if (!isset($this->derivatives[$base_plugin_id])) {
      $plugin_derivatives = [];
      $dashboards = \Drupal::entityQuery('dashboard_entity')
        ->execute();
      foreach ($dashboards as $dashboardID) {
        $dashboard = DashboardEntity::load($dashboardID);
        $machine_name = 'draggable_dashboard_' . $dashboardID;
        $plugin_derivatives[$machine_name] = [
          'id' => $base_plugin_id . PluginBase::DERIVATIVE_SEPARATOR . $machine_name,
          'label' => t('Dashboard: :dashboard', [
            ':dashboard' => $dashboard
              ->get('title'),
          ]),
          'admin_label' => $dashboard
            ->get('title'),
          'description' => $dashboard
            ->get('description'),
        ] + $base_plugin_definition;
      }
      $this->derivatives[$base_plugin_id] = $plugin_derivatives;
    }
    return $this->derivatives[$base_plugin_id];
  }

}

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
DraggableBlockDeriver::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
DraggableBlockDeriver::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions