class EntityBlockContent in Entityblock 8
Retrieves block plugin definitions for all EntityBlocks.
Hierarchy
- class \Drupal\Component\Plugin\Derivative\DeriverBase implements DeriverInterface
- class \Drupal\entityblock\Plugin\Derivative\EntityBlockContent
Expanded class hierarchy of EntityBlockContent
File
- src/
Plugin/ Derivative/ EntityBlockContent.php, line 16 - Contains \Drupal\entityblock\Plugin\Derivative\EntityBlockContent.
Namespace
Drupal\entityblock\Plugin\DerivativeView source
class EntityBlockContent extends DeriverBase {
/**
* {@inheritdoc}
*/
public function getDerivativeDefinitions($base_plugin_definition) {
// Find all entityblock fields.
$field_ids = \Drupal::entityQuery('field_storage_config')
->condition('type', 'entityblock')
->execute();
if ($field_ids) {
// Load all entityblock fields.
$fields = \Drupal::entityTypeManager()
->getStorage('field_storage_config')
->loadMultiple($field_ids);
foreach ($fields as $field) {
// Load all field data.
$entity_query = \Drupal::entityQuery($field
->getTargetEntityTypeId());
$entity_query
->condition($field
->getName() . '.enabled', 1);
$entity_ids = $entity_query
->execute();
// There are entities of this type.
if ($entity_ids) {
$entities = \Drupal::entityTypeManager()
->getStorage($field
->getTargetEntityTypeId())
->loadMultiple($entity_ids);
foreach ($entities as $entity) {
foreach ($entity->{$field
->getName()} as $delta => $item) {
$key = $field
->uuid() . '|' . $entity
->uuid() . '|' . $delta;
$this->derivatives[$key] = $base_plugin_definition;
$this->derivatives[$key]['admin_label'] = $entity
->label() . ' (' . $item->title . ')';
$this->derivatives[$key]['config_dependencies']['content'] = [
$entity
->getConfigDependencyName(),
];
$this->derivatives[$key]['config_dependencies'][$field
->getConfigDependencyKey()] = [
$field
->getConfigDependencyName(),
];
}
}
}
}
}
return parent::getDerivativeDefinitions($base_plugin_definition);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DeriverBase:: |
protected | property | List of derivative definitions. | 1 |
DeriverBase:: |
public | function |
Gets the definition of a derivative plugin. Overrides DeriverInterface:: |
|
EntityBlockContent:: |
public | function |
Gets the definition of all derivatives of a base plugin. Overrides DeriverBase:: |