EntityBlock.php in Entity Blocks 8
File
src/Plugin/Derivative/EntityBlock.php
View source
<?php
namespace Drupal\entity_block\Plugin\Derivative;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class EntityBlock implements ContainerDeriverInterface {
protected $derivatives = [];
protected $basePluginId;
protected $entityTypeManager;
public static function create(ContainerInterface $container, $base_plugin_id) {
return new static($base_plugin_id, $container
->get('entity_type.manager'));
}
public function __construct($base_plugin_id, EntityTypeManagerInterface $entityTypeManager) {
$this->basePluginId = $base_plugin_id;
$this->entityTypeManager = $entityTypeManager;
}
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->entityTypeManager
->getDefinitions() as $entityDefinition) {
if ($entityDefinition
->hasViewBuilderClass()) {
$delta = $entityDefinition
->id();
$this->derivatives[$delta] = [
'category' => 'Entity Block',
'admin_label' => $entityDefinition
->getLabel(),
'config_dependencies' => [
'config' => [],
],
];
$this->derivatives[$delta] += $base_plugin_definition;
}
}
return $this->derivatives;
}
}
Classes
Name |
Description |
EntityBlock |
Provides block plugin definitions for all Entity Block block displays. |