Skip to content
Snippets Groups Projects

Issue #3314957: Add dependencies on selected entities, view modes, and entity browser

1 file
+ 22
30
Compare changes
  • Side-by-side
  • Inline
@@ -6,8 +6,6 @@ use Drupal\Component\Utility\NestedArray;
use Drupal\Component\Utility\SortArray;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Entity\EntityDisplayRepositoryInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
@@ -52,37 +50,14 @@ class EntityBrowserBlock extends BlockBase implements ContainerFactoryPluginInte
*/
protected static $recursiveRenderDepth = [];
/**
* Constructs a new EntityBrowserBlock.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin ID for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager service.
* @param \Drupal\Core\Entity\EntityDisplayRepositoryInterface $entity_display_repository
* The entity display repository.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, EntityDisplayRepositoryInterface $entity_display_repository) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->entityTypeManager = $entity_type_manager;
$this->entityDisplayRepository = $entity_display_repository;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('entity_type.manager'),
$container->get('entity_display.repository')
);
$instance = new static($configuration, $plugin_id, $plugin_definition);
$instance->entityTypeManager = $container->get('entity_type.manager');
$instance->entityDisplayRepository = $container->get('entity_display.repository');
return $instance;
}
/**
@@ -215,7 +190,7 @@ class EntityBrowserBlock extends BlockBase implements ContainerFactoryPluginInte
$storages = [];
$entities = [];
foreach ($ids as $id) {
list($entity_type_id, $entity_id) = explode(':', $id);
[$entity_type_id, $entity_id] = explode(':', $id);
if (!isset($storages[$entity_type_id])) {
$storages[$entity_type_id] = \Drupal::entityTypeManager()->getStorage($entity_type_id);
}
@@ -315,4 +290,21 @@ class EntityBrowserBlock extends BlockBase implements ContainerFactoryPluginInte
return $build;
}
/**
* {@inheritdoc}
*/
public function calculateDependencies() {
$dependencies = parent::calculateDependencies();
if ($entities = static::loadEntitiesByIDs($this->configuration['entity_ids'])) {
foreach ($entities as $id => $entity) {
$dependencies[$entity->getConfigDependencyKey()][] = $entity->getConfigDependencyName();
$view_mode = $this->configuration['view_modes'][$id];
$dependencies['config'][] = 'core.entity_view_display.' . $entity->getEntityTypeId() . '.' . $entity->bundle() . $view_mode;
}
}
// This block is dependent on the entity browser itself.
$dependencies['config'][] = 'entity_browser.browser.' . $this->getDerivativeId();
return $dependencies;
}
}
Loading