class StandardDisplayBuilder in Panels 8.3
Same name and namespace in other branches
- 8.4 src/Plugin/DisplayBuilder/StandardDisplayBuilder.php \Drupal\panels\Plugin\DisplayBuilder\StandardDisplayBuilder
The standard display builder for viewing a PanelsDisplayVariant.
Plugin annotation
@DisplayBuilder(
id = "standard",
label = @Translation("Standard")
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\panels\Plugin\DisplayBuilder\DisplayBuilderBase implements DisplayBuilderInterface
- class \Drupal\panels\Plugin\DisplayBuilder\StandardDisplayBuilder implements ContainerFactoryPluginInterface, PluginWizardInterface
- class \Drupal\panels\Plugin\DisplayBuilder\DisplayBuilderBase implements DisplayBuilderInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of StandardDisplayBuilder
2 files declare their use of StandardDisplayBuilder
- InPlaceEditorDisplayBuilder.php in panels_ipe/
src/ Plugin/ DisplayBuilder/ InPlaceEditorDisplayBuilder.php - StandardDisplayBuilderTest.php in tests/
src/ Unit/ StandardDisplayBuilderTest.php - Contains \Drupal\Tests\panels\Unit\StandardDisplayBuilderTest.
File
- src/
Plugin/ DisplayBuilder/ StandardDisplayBuilder.php, line 33
Namespace
Drupal\panels\Plugin\DisplayBuilderView source
class StandardDisplayBuilder extends DisplayBuilderBase implements PluginWizardInterface, ContainerFactoryPluginInterface {
/**
* The context handler.
*
* @var \Drupal\Core\Plugin\Context\ContextHandlerInterface
*/
protected $contextHandler;
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountInterface
*/
protected $account;
/**
* Constructs a new PanelsDisplayVariant.
*
* @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 definition.
* @param \Drupal\Core\Plugin\Context\ContextHandlerInterface $context_handler
* The context handler.
* @param \Drupal\Core\Session\AccountInterface $account
* The current user.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, ContextHandlerInterface $context_handler, AccountInterface $account) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->contextHandler = $context_handler;
$this->account = $account;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('context.handler'), $container
->get('current_user'));
}
/**
* Build render arrays for each of the regions.
*
* @param array $regions
* The render array representing regions.
* @param array $contexts
* The array of context objects.
*
* @return array
* An associative array, keyed by region ID, containing the render arrays
* representing the content of each region.
*/
protected function buildRegions(array $regions, array $contexts) {
$build = [];
foreach ($regions as $region => $blocks) {
if (!$blocks) {
continue;
}
$region_name = Html::getClass("block-region-{$region}");
$build[$region]['#prefix'] = '<div class="' . $region_name . '">';
$build[$region]['#suffix'] = '</div>';
/** @var \Drupal\Core\Block\BlockPluginInterface[] $blocks */
$weight = 0;
foreach ($blocks as $block_id => $block) {
if ($block instanceof ContextAwarePluginInterface) {
$this->contextHandler
->applyContextMapping($block, $contexts);
}
if ($block
->access($this->account)) {
$block_render_array = [
'#theme' => 'block',
'#attributes' => [],
'#contextual_links' => [],
'#weight' => $weight++,
'#configuration' => $block
->getConfiguration(),
'#plugin_id' => $block
->getPluginId(),
'#base_plugin_id' => $block
->getBaseId(),
'#derivative_plugin_id' => $block
->getDerivativeId(),
];
// Build the block and bubble its attributes up if possible. This
// allows modules like Quickedit to function.
// See \Drupal\block\BlockViewBuilder::preRender() for reference.
$content = $block
->build();
if ($content !== NULL && !Element::isEmpty($content)) {
foreach ([
'#attributes',
'#contextual_links',
] as $property) {
if (isset($content[$property])) {
$block_render_array[$property] += $content[$property];
unset($content[$property]);
}
}
}
// If the block is empty, instead of trying to render the block
// correctly return just #cache, so that the render system knows the
// reasons (cache contexts & tags) why this block is empty.
if (Element::isEmpty($content)) {
$block_render_array = [];
$cacheable_metadata = CacheableMetadata::createFromObject($block_render_array);
$cacheable_metadata
->applyTo($block_render_array);
if (isset($content['#cache'])) {
$block_render_array['#cache'] += $content['#cache'];
}
}
$block_render_array['content'] = $content;
$build[$region][$block_id] = $block_render_array;
}
}
}
return $build;
}
/**
* {@inheritdoc}
*/
public function build(PanelsDisplayVariant $panels_display) {
$regions = $panels_display
->getRegionAssignments();
$contexts = $panels_display
->getContexts();
$layout = $panels_display
->getLayout();
$regions = $this
->buildRegions($regions, $contexts);
if ($layout) {
$regions = $layout
->build($regions);
}
return $regions;
}
/**
* {@inheritdoc}
*/
public function getWizardOperations($cached_values) {
$operations = [];
$operations['content'] = [
'title' => $this
->t('Content'),
'form' => PanelsContentForm::class,
];
return $operations;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
StandardDisplayBuilder:: |
protected | property | The current user. | |
StandardDisplayBuilder:: |
protected | property | The context handler. | |
StandardDisplayBuilder:: |
public | function |
Renders a Panels display. Overrides DisplayBuilderBase:: |
1 |
StandardDisplayBuilder:: |
protected | function | Build render arrays for each of the regions. | |
StandardDisplayBuilder:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
1 |
StandardDisplayBuilder:: |
public | function |
Retrieve a list of FormInterface classes by their step key in the wizard. Overrides PluginWizardInterface:: |
|
StandardDisplayBuilder:: |
public | function |
Constructs a new PanelsDisplayVariant. Overrides PluginBase:: |
1 |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |