public function ViewsBlock::getDerivativeDefinitions

Implements \Drupal\Component\Plugin\Derivative\DerivativeInterface::getDerivativeDefinitions().

Overrides DerivativeInterface::getDerivativeDefinitions

1 call to ViewsBlock::getDerivativeDefinitions()

File

drupal/core/modules/views/lib/Drupal/views/Plugin/Derivative/ViewsBlock.php, line 40
Contains \Drupal\views\Plugin\Derivative\ViewsBlock.

Class

ViewsBlock
Provides block plugin definitions for all Views block displays.

Namespace

Drupal\views\Plugin\Derivative

Code

public function getDerivativeDefinitions(array $base_plugin_definition) {

  // Check all Views for block displays.
  foreach (views_get_all_views() as $view) {

    // Do not return results for disabled views.
    if (!$view
      ->status()) {
      continue;
    }
    $executable = $view
      ->get('executable');
    $executable
      ->initDisplay();
    foreach ($executable->displayHandlers as $display) {

      // Add a block plugin definition for each block display.
      if (isset($display) && !empty($display->definition['uses_hook_block'])) {
        $delta = $view
          ->id() . '-' . $display->display['id'];
        $desc = $display
          ->getOption('block_description');
        if (empty($desc)) {
          if ($display->display['display_title'] == $display->definition['title']) {
            $desc = t('View: !view', array(
              '!view' => $view
                ->label(),
            ));
          }
          else {
            $desc = t('View: !view: !display', array(
              '!view' => $view
                ->label(),
              '!display' => $display->display['display_title'],
            ));
          }
        }
        $this->derivatives[$delta] = array(
          'admin_label' => $desc,
          'cache' => $display
            ->getCacheType(),
        );
        $this->derivatives[$delta] += $base_plugin_definition;
      }
    }
  }
  return $this->derivatives;
}