get('entity.manager')->getStorageController('view') ); } /** * Constructs a ViewsBlock object. * * @param string $base_plugin_id * The base plugin ID. * @param \Drupal\Core\Entity\EntityStorageControllerInterface $view_storage_controller * The entity storage controller to load views. */ public function __construct($base_plugin_id, EntityStorageControllerInterface $view_storage_controller) { $this->basePluginId = $base_plugin_id; $this->viewStorageController = $view_storage_controller; } /** * Implements \Drupal\Component\Plugin\Derivative\DerivativeInterface::getDerivativeDefinition(). */ public function getDerivativeDefinition($derivative_id, array $base_plugin_definition) { if (!empty($this->derivatives) && !empty($this->derivatives[$derivative_id])) { return $this->derivatives[$derivative_id]; } $this->getDerivativeDefinitions($base_plugin_definition); return $this->derivatives[$derivative_id]; } /** * Implements \Drupal\Component\Plugin\Derivative\DerivativeInterface::getDerivativeDefinitions(). */ public function getDerivativeDefinitions(array $base_plugin_definition) { // Check all Views for block displays. foreach ($this->viewStorageController->loadMultiple() as $view) { // Do not return results for disabled views. if (!$view->status()) { continue; } $executable = $view->getExecutable(); $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( 'category' => $display->getOption('block_category'), 'admin_label' => $desc, 'cache' => $display->getCacheType() ); $this->derivatives[$delta] += $base_plugin_definition; } } } return $this->derivatives; } }