class EntityTestBlock
Same name and namespace in other branches
- 11.x core/modules/system/tests/modules/entity_test/src/Plugin/Block/EntityTestBlock.php \Drupal\entity_test\Plugin\Block\EntityTestBlock
Provides a block that renders an entity with parallel placeholder rendering.
Attributes
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements \Drupal\Component\Plugin\PluginInspectionInterface, \Drupal\Component\Plugin\DerivativeInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses \Drupal\Core\DependencyInjection\AutowiredInstanceTrait, \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait extends \Drupal\Component\Plugin\PluginBase
- class \Drupal\Core\Block\BlockBase implements \Drupal\Core\Block\BlockPluginInterface, \Drupal\Core\Plugin\PluginWithFormsInterface, \Drupal\Core\Plugin\PreviewAwarePluginInterface, \Drupal\Core\Render\PreviewFallbackInterface, \Drupal\Core\Plugin\ContextAwarePluginInterface uses \Drupal\Core\Block\BlockPluginTrait, \Drupal\Core\Plugin\ContextAwarePluginTrait, \Drupal\Core\Plugin\ContextAwarePluginAssignmentTrait extends \Drupal\Core\Plugin\PluginBase
- class \Drupal\entity_test\Plugin\Block\EntityTestBlock implements \Drupal\Core\Plugin\ContainerFactoryPluginInterface extends \Drupal\Core\Block\BlockBase
- class \Drupal\Core\Block\BlockBase implements \Drupal\Core\Block\BlockPluginInterface, \Drupal\Core\Plugin\PluginWithFormsInterface, \Drupal\Core\Plugin\PreviewAwarePluginInterface, \Drupal\Core\Render\PreviewFallbackInterface, \Drupal\Core\Plugin\ContextAwarePluginInterface uses \Drupal\Core\Block\BlockPluginTrait, \Drupal\Core\Plugin\ContextAwarePluginTrait, \Drupal\Core\Plugin\ContextAwarePluginAssignmentTrait extends \Drupal\Core\Plugin\PluginBase
- class \Drupal\Core\Plugin\PluginBase uses \Drupal\Core\DependencyInjection\AutowiredInstanceTrait, \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait extends \Drupal\Component\Plugin\PluginBase
Expanded class hierarchy of EntityTestBlock
File
-
core/
modules/ system/ tests/ modules/ entity_test/ src/ Plugin/ Block/ EntityTestBlock.php, line 16
Namespace
Drupal\entity_test\Plugin\BlockView source
class EntityTestBlock extends BlockBase implements ContainerFactoryPluginInterface {
public function __construct(array $configuration, $plugin_id, $plugin_definition, protected EntityTypeManagerInterface $entityTypeManager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
}
/**
* {@inheritdoc}
*/
public function defaultConfiguration() : array {
return [
'entity_type_id' => 'entity_test',
'entity_id' => NULL,
] + parent::defaultConfiguration();
}
/**
* {@inheritdoc}
*/
public function createPlaceholder() : bool {
// Render as a placeholder so this block is rendered in a Fiber, enabling
// tests to verify concurrent entity rendering behavior.
return TRUE;
}
/**
* {@inheritdoc}
*/
public function build() : array {
$entity_type_id = $this->configuration['entity_type_id'];
$entity = $this->entityTypeManager
->getStorage($entity_type_id)
->load($this->configuration['entity_id']);
if ($entity) {
return $this->entityTypeManager
->getViewBuilder($entity_type_id)
->view($entity);
}
return [];
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.