Defines the display entity.
@Plugin(
id = "display",
label = @Translation("Display"),
module = "layout",
controller_class = "Drupal\Core\Config\Entity\ConfigStorageController",
config_prefix = "display.bound",
entity_keys = {
"id" = "id",
"uuid" = "uuid"
}
)
Expanded class hierarchy of Display
class Display extends DisplayBase implements BoundDisplayInterface {
/**
* A two-level array expressing block ordering within regions.
*
* The outer array is associative, keyed on region name. Each inner array is
* indexed, with the config address of a block as values and sorted according
* to order in which those blocks should appear in that region.
*
* This property is not stored statically in config, but is derived at runtime
* by DisplayBase::sortBlocks(). It is not stored statically because that
* would make using weights for ordering more difficult, and weights make
* external mass manipulation of displays much easier.
*
* @var array
*/
protected $blocksInRegions;
/**
* The layout instance being used to serve this page.
*
* @var \Drupal\layout\Plugin\LayoutInterface
*/
protected $layoutInstance;
/**
* The name of the layout plugin to use.
*
* @var string
*/
public $layout;
/**
* The settings with which to instantiate the layout plugin.
*
* @var array
*/
public $layoutSettings = array();
/**
* Implements BoundDisplayInterface::getSortedBlocksByRegion().
*
* @throws \Exception
*/
public function getSortedBlocksByRegion($region) {
if ($this->blocksInRegions === NULL) {
$this
->sortBlocks();
}
if (!isset($this->blocksInRegions[$region])) {
throw new \Exception(sprintf("Region %region does not exist in layout %layout", array(
'%region' => $region,
'%layout' => $this
->getLayoutInstance()->name,
)), E_RECOVERABLE_ERROR);
}
return $this->blocksInRegions[$region];
}
/**
* Implements BoundDisplayInterface::getAllSortedBlocks().
*/
public function getAllSortedBlocks() {
if ($this->blocksInRegions === NULL) {
$this
->sortBlocks();
}
return $this->blocksInRegions;
}
/**
* Transform the stored blockConfig into a sorted, region-oriented array.
*/
protected function sortBlocks() {
$layout_instance = $this
->getLayoutInstance();
if ($this->layout !== $layout_instance
->getPluginId()) {
$block_config = $this
->mapBlocksToLayout($layout_instance);
}
else {
$block_config = $this->blockInfo;
}
$this->blocksInRegions = array();
$regions = array_fill_keys(array_keys($layout_instance
->getRegions()), array());
foreach ($block_config as $config_name => $info) {
$regions[$info['region']][$config_name] = $info;
}
foreach ($regions as $region_name => &$blocks) {
uasort($blocks, 'drupal_sort_weight');
$this->blocksInRegions[$region_name] = array_keys($blocks);
}
}
/**
* Implements BoundDisplayInterface::remapToLayout().
*/
public function remapToLayout(LayoutInterface $layout) {
$this->blockInfo = $this
->mapBlocksToLayout($layout);
$this
->setLayout($layout
->getPluginId());
}
/**
* Set the contained layout plugin.
*
* @param string $plugin_id
* The plugin id of the desired layout plugin.
*/
public function setLayout($plugin_id) {
// @todo verification?
$this->layout = $plugin_id;
$this->layoutInstance = NULL;
$this->blocksInRegions = NULL;
}
/**
* Implements BoundDisplayInterface::generateUnboundDisplay().
*
* @throws \Exception
*/
public function generateUnboundDisplay($id, $entity_type = 'unbound_display') {
$block_info = $this
->getAllBlockInfo();
foreach ($block_info as &$info) {
unset($info['region']);
}
$values = array(
'blockInfo' => $block_info,
'id' => $id,
);
$entity = entity_create($entity_type, $values);
if (!$entity instanceof UnboundDisplayInterface) {
throw new \Exception(sprintf('Attempted to create an unbound display using an invalid entity type.'), E_RECOVERABLE_ERROR);
}
return $entity;
}
/**
* Returns the instantiated layout object.
*
* @throws \Exception
*/
public function getLayoutInstance() {
if ($this->layoutInstance === NULL) {
if (empty($this->layout)) {
throw new \Exception(sprintf('Display "%id" had no layout plugin attached.', array(
'%id' => $this
->id(),
)), E_RECOVERABLE_ERROR);
}
$this->layoutInstance = layout_manager()
->createInstance($this->layout, $this->layoutSettings);
// @todo add handling for remapping if the layout could not be found
}
return $this->layoutInstance;
}
}
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigEntityBase:: |
protected | property | The original ID of the configuration entity. | |
ConfigEntityBase:: |
public | function |
Overrides Entity::createDuplicate(). Overrides Entity:: |
1 |
ConfigEntityBase:: |
public | function |
Overrides Entity::get(). Overrides Entity:: |
1 |
ConfigEntityBase:: |
public | function |
Implements ConfigEntityInterface::getOriginalID(). Overrides ConfigEntityInterface:: |
|
ConfigEntityBase:: |
final public | function |
Overrides Entity::isNew(). Overrides Entity:: |
|
ConfigEntityBase:: |
public | function |
Overrides Entity::set(). Overrides Entity:: |
|
ConfigEntityBase:: |
public | function |
Implements ConfigEntityInterface::setOriginalID(). Overrides ConfigEntityInterface:: |
|
ConfigEntityBase:: |
public static | function | Helper callback for uasort() to sort configuration entities by weight and label. | |
ConfigEntityBase:: |
public | function |
Overrides Entity::__construct(). Overrides Entity:: |
2 |
Display:: |
protected | property | A two-level array expressing block ordering within regions. | |
Display:: |
public | property | The name of the layout plugin to use. | |
Display:: |
protected | property | The layout instance being used to serve this page. | |
Display:: |
public | property | The settings with which to instantiate the layout plugin. | |
Display:: |
public | function |
Implements BoundDisplayInterface::generateUnboundDisplay(). Overrides BoundDisplayInterface:: |
|
Display:: |
public | function |
Implements BoundDisplayInterface::getAllSortedBlocks(). Overrides BoundDisplayInterface:: |
|
Display:: |
public | function |
Returns the instantiated layout object. Overrides BoundDisplayInterface:: |
|
Display:: |
public | function |
Implements BoundDisplayInterface::getSortedBlocksByRegion(). Overrides BoundDisplayInterface:: |
|
Display:: |
public | function |
Implements BoundDisplayInterface::remapToLayout(). Overrides BoundDisplayInterface:: |
|
Display:: |
public | function |
Set the contained layout plugin. Overrides BoundDisplayInterface:: |
|
Display:: |
protected | function | Transform the stored blockConfig into a sorted, region-oriented array. | |
DisplayBase:: |
protected | property | Contains all block configuration. | |
DisplayBase:: |
public | property | The ID (config name) identifying a specific display object. | |
DisplayBase:: |
public | property | The UUID identifying a specific display object. | |
DisplayBase:: |
public | function |
Implements DisplayInterface::getAllBlockInfo(). Overrides DisplayInterface:: |
|
DisplayBase:: |
public | function |
Implements DisplayInterface::getAllRegionTypes(). Overrides DisplayInterface:: |
|
DisplayBase:: |
public | function |
Implements DisplayInterface::mapBlocksToLayout(). Overrides DisplayInterface:: |
|
Entity:: |
protected | property | Boolean indicating whether the entity should be forced to be new. | |
Entity:: |
protected | property | The entity type. | |
Entity:: |
protected | property | Indicates whether this is the default revision. | 1 |
Entity:: |
public | property | The language code of the entity's default language. | 4 |
Entity:: |
protected | property | Boolean indicating whether a new revision should be created on save. | |
Entity:: |
public | function |
Implements AccessibleInterface::access(). Overrides AccessibleInterface:: |
|
Entity:: |
public | function |
Implements EntityInterface::bundle(). Overrides EntityInterface:: |
4 |
Entity:: |
public | function |
Implements EntityInterface::delete(). Overrides EntityInterface:: |
|
Entity:: |
public | function |
Implements EntityInterface::enforceIsNew(). Overrides EntityInterface:: |
|
Entity:: |
public | function |
Implements EntityInterface::entityInfo(). Overrides EntityInterface:: |
|
Entity:: |
public | function |
Implements EntityInterface::entityType(). Overrides EntityInterface:: |
|
Entity:: |
public | function | Implements ComplexDataInterface::getIterator(). | 1 |
Entity:: |
public | function |
Implements ComplexDataInterface::getProperties(). Overrides ComplexDataInterface:: |
1 |
Entity:: |
public | function |
Implements ComplexDataInterface::getPropertyDefinition(). Overrides ComplexDataInterface:: |
1 |
Entity:: |
public | function |
Implements ComplexDataInterface::getPropertyDefinitions(). Overrides ComplexDataInterface:: |
1 |
Entity:: |
public | function |
Implements ComplexDataInterface::getPropertyValues(). Overrides ComplexDataInterface:: |
1 |
Entity:: |
public | function |
Implements Drupal\Core\Entity\EntityInterface::getRevisionId(). Overrides EntityInterface:: |
3 |
Entity:: |
public | function |
Implements TranslatableInterface::getTranslation(). Overrides TranslatableInterface:: |
1 |
Entity:: |
public | function |
Implements TranslatableInterface::getTranslationLanguages(). Overrides TranslatableInterface:: |
1 |
Entity:: |
public | function |
Implements EntityInterface::id(). Overrides EntityInterface:: |
10 |
Entity:: |
public | function |
Implements Drupal\Core\Entity\EntityInterface::isDefaultRevision(). Overrides EntityInterface:: |
1 |
Entity:: |
public | function |
Implements ComplexDataInterface::isEmpty(). Overrides ComplexDataInterface:: |
1 |
Entity:: |
public | function |
Implements EntityInterface::isNewRevision(). Overrides EntityInterface:: |
|
Entity:: |
public | function |
Implements EntityInterface::label(). Overrides EntityInterface:: |
1 |
Entity:: |
public | function |
Implements TranslatableInterface::language(). Overrides TranslatableInterface:: |
1 |
Entity:: |
public | function |
Implements EntityInterface::save(). Overrides EntityInterface:: |
3 |
Entity:: |
public | function |
Implements EntityInterface::setNewRevision(). Overrides EntityInterface:: |
|
Entity:: |
public | function |
Implements ComplexDataInterface::setPropertyValues(). Overrides ComplexDataInterface:: |
1 |
Entity:: |
public | function | Returns the languages the entity is translated to. | |
Entity:: |
public | function |
Implements EntityInterface::uri(). Overrides EntityInterface:: |
1 |
Entity:: |
public | function |
Implements EntityInterface::uuid(). Overrides EntityInterface:: |
1 |