Same filename in this branch
- 10 core/modules/views/src/Plugin/Block/ViewsBlock.php
- 10 core/modules/views/src/Plugin/Derivative/ViewsBlock.php
Same filename and directory in other branches
- 8.9.x core/modules/views/src/Plugin/Derivative/ViewsBlock.php
- 9 core/modules/views/src/Plugin/Derivative/ViewsBlock.php
Namespace
Drupal\views\Plugin\Derivative
File
core/modules/views/src/Plugin/Derivative/ViewsBlock.php
View source
<?php
namespace Drupal\views\Plugin\Derivative;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Symfony\Component\DependencyInjection\ContainerInterface;
class ViewsBlock implements ContainerDeriverInterface {
protected $derivatives = [];
protected $basePluginId;
protected $viewStorage;
public static function create(ContainerInterface $container, $base_plugin_id) {
return new static($base_plugin_id, $container
->get('entity_type.manager')
->getStorage('view'));
}
public function __construct($base_plugin_id, EntityStorageInterface $view_storage) {
$this->basePluginId = $base_plugin_id;
$this->viewStorage = $view_storage;
}
public function getDerivativeDefinition($derivative_id, $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];
}
public function getDerivativeDefinitions($base_plugin_definition) {
foreach ($this->viewStorage
->loadMultiple() as $view) {
if (!$view
->status()) {
continue;
}
$executable = $view
->getExecutable();
$executable
->initDisplay();
foreach ($executable->displayHandlers as $display) {
if (isset($display) && !empty($display->definition['uses_hook_block'])) {
$delta = $view
->id() . '-' . $display->display['id'];
$admin_label = $display
->getOption('block_description');
if (empty($admin_label)) {
if ($display->display['display_title'] == $display->definition['title']) {
$admin_label = $view
->label();
}
else {
$admin_label = new TranslatableMarkup('@view: @display', [
'@view' => $view
->label(),
'@display' => $display->display['display_title'],
]);
}
}
$this->derivatives[$delta] = [
'category' => $display
->getOption('block_category'),
'admin_label' => $admin_label,
'config_dependencies' => [
'config' => [
$view
->getConfigDependencyName(),
],
],
];
foreach ($display
->getHandlers('argument') as $argument_name => $argument) {
if ($context_definition = $argument
->getContextDefinition()) {
$this->derivatives[$delta]['context_definitions'][$argument_name] = $context_definition;
}
}
$this->derivatives[$delta] += $base_plugin_definition;
}
}
}
return $this->derivatives;
}
}
Classes
Name |
Description |
ViewsBlock |
Provides block plugin definitions for all Views block displays. |