class Display

Defines the display entity.

Plugin annotation


@EntityType(
  id = "display",
  label = @Translation("Display"),
  module = "layout",
  controllers = {
    "storage" = "Drupal\Core\Config\Entity\ConfigStorageController"
  },
  config_prefix = "display.bound",
  entity_keys = {
    "id" = "id",
    "uuid" = "uuid"
  }
)

Hierarchy

Expanded class hierarchy of Display

1 file declares its use of Display
DisplayInternalLogicTest.php in drupal/core/modules/layout/lib/Drupal/layout/Tests/DisplayInternalLogicTest.php
Definition of \Drupal\layout\Tests\DisplayInternalLogicTest.
7 string references to 'Display'
DisplayInternalLogicTest::getInfo in drupal/core/modules/layout/lib/Drupal/layout/Tests/DisplayInternalLogicTest.php
DisplayTest::getInfo in drupal/core/modules/views/lib/Drupal/views/Tests/Plugin/DisplayTest.php
ReorderDisplays::buildForm in drupal/core/modules/views_ui/lib/Drupal/views_ui/Form/Ajax/ReorderDisplays.php
Implements \Drupal\Core\Form\FormInterface::buildForm().
Result::buildOptionsForm in drupal/core/modules/views/lib/Drupal/views/Plugin/views/area/Result.php
Default options form that provides the label widget that all fields should have.
template_preprocess_views_ui_view_info in drupal/core/modules/views_ui/views_ui.theme.inc
Implements hook_preprocess_HOOK() for theme_views_ui_view_info().

... See full list

File

drupal/core/modules/layout/lib/Drupal/layout/Plugin/Core/Entity/Display.php, line 34
Definition of Drupal\layout\Plugin\Core\Entity\Display.

Namespace

Drupal\layout\Plugin\Core\Entity
View source
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;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigEntityBase::$originalID protected property The original ID of the configuration entity.
ConfigEntityBase::$status public property The enabled/disabled status of the configuration entity. 1
ConfigEntityBase::createDuplicate public function Overrides Entity::createDuplicate(). Overrides Entity::createDuplicate 2
ConfigEntityBase::disable public function Implements \Drupal\Core\Config\Entity\ConfigEntityInterface::disable(). Overrides ConfigEntityInterface::disable 1
ConfigEntityBase::enable public function Implements \Drupal\Core\Config\Entity\ConfigEntityInterface::enable(). Overrides ConfigEntityInterface::enable
ConfigEntityBase::get public function Overrides Entity::get(). Overrides Entity::get 2
ConfigEntityBase::getExportProperties public function Overrides \Drupal\Core\Entity\Entity::getExportProperties(). Overrides Entity::getExportProperties 9
ConfigEntityBase::getOriginalID public function Implements ConfigEntityInterface::getOriginalID(). Overrides ConfigEntityInterface::getOriginalID
ConfigEntityBase::isNew public function Overrides Entity::isNew(). Overrides Entity::isNew
ConfigEntityBase::set public function Overrides Entity::set(). Overrides Entity::set
ConfigEntityBase::setOriginalID public function Implements ConfigEntityInterface::setOriginalID(). Overrides ConfigEntityInterface::setOriginalID
ConfigEntityBase::setStatus public function Implements \Drupal\Core\Config\Entity\ConfigEntityInterface::setStatus(). Overrides ConfigEntityInterface::setStatus
ConfigEntityBase::sort public static function Helper callback for uasort() to sort configuration entities by weight and label. 2
ConfigEntityBase::status public function Implements \Drupal\Core\Config\Entity\ConfigEntityInterface::status(). Overrides ConfigEntityInterface::status 1
ConfigEntityBase::__construct public function Overrides Entity::__construct(). Overrides Entity::__construct 9
Display::$blocksInRegions protected property A two-level array expressing block ordering within regions.
Display::$layout public property The name of the layout plugin to use.
Display::$layoutInstance protected property The layout instance being used to serve this page.
Display::$layoutSettings public property The settings with which to instantiate the layout plugin.
Display::generateUnboundDisplay public function Implements BoundDisplayInterface::generateUnboundDisplay(). Overrides BoundDisplayInterface::generateUnboundDisplay
Display::getAllSortedBlocks public function Implements BoundDisplayInterface::getAllSortedBlocks(). Overrides BoundDisplayInterface::getAllSortedBlocks
Display::getLayoutInstance public function Returns the instantiated layout object. Overrides BoundDisplayInterface::getLayoutInstance
Display::getSortedBlocksByRegion public function Implements BoundDisplayInterface::getSortedBlocksByRegion(). Overrides BoundDisplayInterface::getSortedBlocksByRegion
Display::remapToLayout public function Implements BoundDisplayInterface::remapToLayout(). Overrides BoundDisplayInterface::remapToLayout
Display::setLayout public function Set the contained layout plugin. Overrides BoundDisplayInterface::setLayout
Display::sortBlocks protected function Transform the stored blockConfig into a sorted, region-oriented array.
DisplayBase::$blockInfo protected property Contains all block configuration.
DisplayBase::$id public property The ID (config name) identifying a specific display object.
DisplayBase::$uuid public property The UUID identifying a specific display object.
DisplayBase::getAllBlockInfo public function Implements DisplayInterface::getAllBlockInfo(). Overrides DisplayInterface::getAllBlockInfo
DisplayBase::getAllRegionTypes public function Implements DisplayInterface::getAllRegionTypes(). Overrides DisplayInterface::getAllRegionTypes
DisplayBase::mapBlocksToLayout public function Implements DisplayInterface::mapBlocksToLayout(). Overrides DisplayInterface::mapBlocksToLayout
Entity::$enforceIsNew protected property Boolean indicating whether the entity should be forced to be new.
Entity::$entityType protected property The entity type.
Entity::$isDefaultRevision protected property Indicates whether this is the default revision. 1
Entity::$langcode public property The language code of the entity's default language. 7
Entity::$newRevision protected property Boolean indicating whether a new revision should be created on save.
Entity::access public function Implements \Drupal\Core\TypedData\AccessibleInterface::access(). Overrides AccessibleInterface::access
Entity::bundle public function Implements \Drupal\Core\Entity\EntityInterface::bundle(). Overrides EntityInterface::bundle 4
Entity::delete public function Implements \Drupal\Core\Entity\EntityInterface::delete(). Overrides EntityInterface::delete 3
Entity::enforceIsNew public function Implements \Drupal\Core\Entity\EntityInterface::enforceIsNew(). Overrides EntityInterface::enforceIsNew
Entity::entityInfo public function Implements \Drupal\Core\Entity\EntityInterface::entityInfo(). Overrides EntityInterface::entityInfo
Entity::entityType public function Implements \Drupal\Core\Entity\EntityInterface::entityType(). Overrides EntityInterface::entityType
Entity::getBCEntity public function Implements \Drupal\Core\Entity\EntityInterface::getBCEntity(). Overrides EntityInterface::getBCEntity 1
Entity::getConstraints public function Implements \Drupal\Core\TypedData\TypedDataInterface::getConstraints(). Overrides TypedDataInterface::getConstraints
Entity::getDefinition public function Implements \Drupal\Core\TypedData\TypedDataInterface::getDefinition(). Overrides TypedDataInterface::getDefinition
Entity::getIterator public function Implements \Drupal\Core\TypedData\ComplexDataInterface::getIterator(). 1
Entity::getName public function Implements \Drupal\Core\TypedData\TypedDataInterface::getName(). Overrides TypedDataInterface::getName
Entity::getNGEntity public function Implements \Drupal\Core\Entity\EntityInterface::getNGEntity(). Overrides EntityInterface::getNGEntity
Entity::getParent public function Implements \Drupal\Core\TypedData\TypedDataInterface::getParent(). Overrides TypedDataInterface::getParent
Entity::getProperties public function Implements \Drupal\Core\TypedData\ComplexDataInterface::getProperties(). Overrides ComplexDataInterface::getProperties 1
Entity::getPropertyDefinition public function Implements \Drupal\Core\TypedData\ComplexDataInterface::getPropertyDefinition(). Overrides ComplexDataInterface::getPropertyDefinition 1
Entity::getPropertyDefinitions public function Implements \Drupal\Core\TypedData\ComplexDataInterface::getPropertyDefinitions(). Overrides ComplexDataInterface::getPropertyDefinitions 1
Entity::getPropertyPath public function Implements \Drupal\Core\TypedData\TypedDataInterface::getPropertyPath(). Overrides TypedDataInterface::getPropertyPath
Entity::getPropertyValues public function Implements \Drupal\Core\TypedData\ComplexDataInterface::getPropertyValues(). Overrides ComplexDataInterface::getPropertyValues 1
Entity::getRevisionId public function Implements \Drupal\Core\Entity\EntityInterface::getRevisionId(). Overrides EntityInterface::getRevisionId 4
Entity::getRoot public function Implements \Drupal\Core\TypedData\TypedDataInterface::getRoot(). Overrides TypedDataInterface::getRoot
Entity::getString public function Implements \Drupal\Core\TypedData\TypedDataInterface::getString(). Overrides TypedDataInterface::getString
Entity::getTranslation public function Implements \Drupal\Core\TypedData\TranslatableInterface::getTranslation(). Overrides TranslatableInterface::getTranslation 1
Entity::getTranslationLanguages public function Implements \Drupal\Core\TypedData\TranslatableInterface::getTranslationLanguages(). Overrides TranslatableInterface::getTranslationLanguages 1
Entity::getType public function Implements \Drupal\Core\TypedData\TypedDataInterface::getType(). Overrides TypedDataInterface::getType 2
Entity::getValue public function Implements \Drupal\Core\TypedData\TypedDataInterface::getValue(). Overrides TypedDataInterface::getValue
Entity::id public function Implements \Drupal\Core\Entity\EntityInterface::id(). Overrides EntityInterface::id 11
Entity::isDefaultRevision public function Implements \Drupal\Core\Entity\EntityInterface::isDefaultRevision(). Overrides EntityInterface::isDefaultRevision 1
Entity::isEmpty public function Implements \Drupal\Core\TypedData\ComplexDataInterface::isEmpty(). Overrides ComplexDataInterface::isEmpty 1
Entity::isNewRevision public function Implements \Drupal\Core\Entity\EntityInterface::isNewRevision(). Overrides EntityInterface::isNewRevision
Entity::isTranslatable public function Implements \Drupal\Core\Entity\EntityInterface::isTranslatable(). Overrides EntityInterface::isTranslatable
Entity::label public function Implements \Drupal\Core\Entity\EntityInterface::label(). Overrides EntityInterface::label 4
Entity::language public function Implements \Drupal\Core\TypedData\TranslatableInterface::language(). Overrides TranslatableInterface::language 1
Entity::onChange public function Implements \Drupal\Core\TypedData\ComplexDataInterface::onChange(). Overrides ComplexDataInterface::onChange
Entity::save public function Implements \Drupal\Core\Entity\EntityInterface::save(). Overrides EntityInterface::save 6
Entity::setContext public function Implements \Drupal\Core\TypedData\TypedDataInterface::setContext(). Overrides TypedDataInterface::setContext
Entity::setNewRevision public function Implements \Drupal\Core\Entity\EntityInterface::setNewRevision(). Overrides EntityInterface::setNewRevision
Entity::setPropertyValues public function Implements \Drupal\Core\TypedData\ComplexDataInterface::setPropertyValues(). Overrides ComplexDataInterface::setPropertyValues 1
Entity::setValue public function Implements \Drupal\Core\TypedData\TypedDataInterface::setValue(). Overrides TypedDataInterface::setValue
Entity::translations public function Returns the languages the entity is translated to. 1
Entity::uri public function Implements \Drupal\Core\Entity\EntityInterface::uri(). Overrides EntityInterface::uri 8
Entity::uriRelationships public function Returns a list of URI relationships supported by this entity. Overrides EntityInterface::uriRelationships
Entity::uuid public function Implements \Drupal\Core\Entity\EntityInterface::uuid(). Overrides EntityInterface::uuid 1
Entity::validate public function Implements \Drupal\Core\TypedData\TypedDataInterface::validate(). Overrides TypedDataInterface::validate 1