You are here

class LayoutBuilderDisplayVariant in Page Manager 8.4

Provides a Layout Builder variant.

Plugin annotation


@DisplayVariant(
  id = "layout_builder",
  admin_label = @Translation("Layout Builder")
)

Hierarchy

Expanded class hierarchy of LayoutBuilderDisplayVariant

2 files declare their use of LayoutBuilderDisplayVariant
PageManagerLayoutBuilderStorage.php in src/Plugin/LayoutBuilderStorage/PageManagerLayoutBuilderStorage.php
PageManagerSectionStorage.php in src/Plugin/SectionStorage/PageManagerSectionStorage.php

File

src/Plugin/DisplayVariant/LayoutBuilderDisplayVariant.php, line 21

Namespace

Drupal\page_manager\Plugin\DisplayVariant
View source
class LayoutBuilderDisplayVariant extends VariantBase implements PluginWizardInterface, ContextAwareVariantInterface {
  use SectionStorageTrait;
  use LayoutEntityHelperTrait;

  /**
   * An array of collected contexts.
   *
   * This is only used on runtime, and is not stored.
   *
   * @var \Drupal\Component\Plugin\Context\ContextInterface[]
   */
  protected $contexts = [];

  /**
   * {@inheritdoc}
   */
  public function build() {
    $build = [];
    $contexts = $this
      ->getContexts();
    foreach ($this
      ->getSections() as $delta => $section) {
      $build[$delta] = $section
        ->toRenderArray($contexts);
    }
    return $build;
  }

  /**
   * {@inheritdoc}
   */
  public function defaultConfiguration() {
    return parent::defaultConfiguration() + [
      'sections' => [],
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function getWizardOperations($cached_values) {
    $operations = [];
    $operations['layout_builder'] = [
      'title' => $this
        ->t('Layout'),
      'form' => LayoutBuilderForm::class,
    ];
    return $operations;
  }

  /**
   * {@inheritdoc}
   */
  protected function setSections(array $sections) {
    $this->configuration['sections'] = array_values($sections);
  }

  /**
   * {@inheritdoc}
   */
  public function getSections() {
    if (!isset($this->configuration['sections'])) {
      $this->configuration['sections'] = [];
    }
    return $this->configuration['sections'];
  }

  /**
   * Returns instance of the layout plugin used by this page variant.
   *
   * @return \Drupal\Core\Layout\LayoutInterface
   *   A layout plugin instance.
   */
  public function getLayout() {
    if (!isset($this->layout)) {
      $this->layout = $this->layoutManager
        ->createInstance($this->configuration['layout'], $this->configuration['layout_settings']);
    }
    return $this->layout;
  }

  /**
   * {@inheritdoc}
   */
  public function getContexts() {
    return $this->contexts;
  }

  /**
   * {@inheritdoc}
   */
  public function setContexts(array $contexts) {
    $this->contexts = $contexts;
    return $this;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CacheableDependencyTrait::$cacheContexts protected property Cache contexts.
CacheableDependencyTrait::$cacheMaxAge protected property Cache max-age.
CacheableDependencyTrait::$cacheTags protected property Cache tags.
CacheableDependencyTrait::getCacheContexts public function 3
CacheableDependencyTrait::getCacheMaxAge public function 3
CacheableDependencyTrait::getCacheTags public function 3
CacheableDependencyTrait::setCacheability protected function Sets cacheability; useful for value object constructors.
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
DependencyTrait::$dependencies protected property The object's dependencies.
DependencyTrait::addDependencies protected function Adds multiple dependencies.
DependencyTrait::addDependency protected function Adds a dependency.
LayoutBuilderDisplayVariant::$contexts protected property An array of collected contexts.
LayoutBuilderDisplayVariant::build public function Builds and returns the renderable array for the display variant. Overrides VariantInterface::build
LayoutBuilderDisplayVariant::buildConfigurationForm public function Form constructor. Overrides VariantBase::buildConfigurationForm
LayoutBuilderDisplayVariant::defaultConfiguration public function Gets default configuration for this plugin. Overrides VariantBase::defaultConfiguration
LayoutBuilderDisplayVariant::getContexts public function Gets the values for all defined contexts. Overrides ContextAwareVariantInterface::getContexts
LayoutBuilderDisplayVariant::getLayout public function Returns instance of the layout plugin used by this page variant.
LayoutBuilderDisplayVariant::getSections public function
LayoutBuilderDisplayVariant::getWizardOperations public function Retrieve a list of FormInterface classes by their step key in the wizard. Overrides PluginWizardInterface::getWizardOperations
LayoutBuilderDisplayVariant::setContexts public function Sets the context values for this display variant. Overrides ContextAwareVariantInterface::setContexts
LayoutBuilderDisplayVariant::setSections protected function Stores the information for all sections. Overrides SectionStorageTrait::setSections
LayoutEntityHelperTrait::$sectionStorageManager protected property The section storage manager. 1
LayoutEntityHelperTrait::getEntitySections protected function Gets the sections for an entity if any.
LayoutEntityHelperTrait::getInlineBlockComponents protected function Gets components that have Inline Block plugins.
LayoutEntityHelperTrait::getInlineBlockRevisionIdsInSections protected function Gets revision IDs for layout sections.
LayoutEntityHelperTrait::getSectionStorageForEntity protected function Gets the section storage for an entity.
LayoutEntityHelperTrait::isEntityUsingFieldOverride Deprecated protected function Determines if an entity is using a field for the layout override.
LayoutEntityHelperTrait::isLayoutCompatibleEntity protected function Determines if an entity can have a layout.
LayoutEntityHelperTrait::originalEntityUsesDefaultStorage protected function Determines if the original entity used the default section storage.
LayoutEntityHelperTrait::sectionStorageManager private function Gets the section storage manager. 1
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
PluginDependencyTrait::calculatePluginDependencies protected function Calculates and adds dependencies of a specific plugin instance. 1
PluginDependencyTrait::getPluginDependencies protected function Calculates and returns dependencies of a specific plugin instance.
PluginDependencyTrait::moduleHandler protected function Wraps the module handler. 1
PluginDependencyTrait::themeHandler protected function Wraps the theme handler. 1
RefinableCacheableDependencyTrait::addCacheableDependency public function 1
RefinableCacheableDependencyTrait::addCacheContexts public function
RefinableCacheableDependencyTrait::addCacheTags public function
RefinableCacheableDependencyTrait::mergeCacheMaxAge public function
SectionStorageTrait::addBlankSection protected function Adds a blank section to the list.
SectionStorageTrait::appendSection public function
SectionStorageTrait::count public function
SectionStorageTrait::getSection public function
SectionStorageTrait::hasBlankSection protected function Indicates if this section list contains a blank section.
SectionStorageTrait::hasSection protected function Indicates if there is a section at the specified delta.
SectionStorageTrait::insertSection public function
SectionStorageTrait::removeAllSections public function
SectionStorageTrait::removeSection public function
SectionStorageTrait::setSection protected function Sets the section for the given delta on the display.
SectionStorageTrait::__clone public function Magic method: Implements a deep clone.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
VariantBase::access public function Determines if this display variant is accessible. Overrides VariantInterface::access
VariantBase::adminLabel public function Returns the admin-facing display variant label. Overrides VariantInterface::adminLabel
VariantBase::calculateDependencies public function Calculates dependencies for the configured plugin. Overrides DependentPluginInterface::calculateDependencies
VariantBase::getConfiguration public function Gets this plugin's configuration. Overrides ConfigurableInterface::getConfiguration
VariantBase::getWeight public function Returns the weight of the display variant. Overrides VariantInterface::getWeight
VariantBase::id public function Returns the unique ID for the display variant. Overrides VariantInterface::id
VariantBase::label public function Returns the user-facing display variant label. Overrides VariantInterface::label
VariantBase::setConfiguration public function Sets the configuration for this plugin instance. Overrides ConfigurableInterface::setConfiguration
VariantBase::setWeight public function Sets the weight of the display variant. Overrides VariantInterface::setWeight
VariantBase::submitConfigurationForm public function Form submission handler. Overrides PluginFormInterface::submitConfigurationForm
VariantBase::validateConfigurationForm public function Form validation handler. Overrides PluginFormInterface::validateConfigurationForm
VariantBase::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase::__construct 1