You are here

class PanelsEverywhereDisplayVariant in Panels Everywhere 8

Same name and namespace in other branches
  1. 8.4 src/Plugin/DisplayVariant/PanelsEverywhereDisplayVariant.php \Drupal\panels_everywhere\Plugin\DisplayVariant\PanelsEverywhereDisplayVariant

Provides a display variant that simply contains blocks.

@todo: This shouldn't be necessary - the PanelsDisplayVariant should implement PageVariantInterface, because, it's easy and then it can be used to render the full page.

Plugin annotation


@DisplayVariant(
  id = "panels_everywhere_variant",
  admin_label = @Translation("Panels Everywhere")
)

Hierarchy

Expanded class hierarchy of PanelsEverywhereDisplayVariant

File

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

Namespace

Drupal\panels_everywhere\Plugin\DisplayVariant
View source
class PanelsEverywhereDisplayVariant extends PanelsDisplayVariant implements PageVariantInterface {

  /**
   * The render array representing the main page content.
   *
   * @var array
   */
  protected $mainContent = [];

  /**
   * The title for the display variant.
   *
   * @var string
   */
  protected $title;

  /**
   * Sets the title for the page being rendered.
   *
   * @param string|array $title
   *   The page title: either a string for plain titles or a render array for
   *   formatted titles.
   *
   * @return $this
   */
  public function setTitle($title) {
    $this->title = $title;
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function setMainContent(array $main_content) {
    $this->mainContent = $main_content;
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function build() {
    $main_content_included = NULL;
    $this
      ->setPageTitle($this->title);
    foreach ($this
      ->getRegionAssignments() as $region => $blocks) {
      if (!$blocks) {
        continue;
      }
      foreach ($blocks as $block_id => $block) {
        if ($block instanceof MainContentBlockPluginInterface) {
          $block
            ->setMainContent($this->mainContent);
          $main_content_included = array(
            $region,
            $block_id,
          );
        }
      }
    }

    // Build it the render array!
    $build = parent::build();

    // Copied from BlockPageVariant.php.
    // The main content block cannot be cached: it is a placeholder for the
    // render array returned by the controller. It should be rendered as-is,
    // with other placed blocks "decorating" it.
    if (!empty($main_content_included)) {
      list($region, $block_id) = $main_content_included;
      unset($build[$region][$block_id]['#cache']['keys']);
    }
    return $build;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CacheableDependencyInterface::getCacheContexts public function The cache contexts associated with this object. 34
CacheableDependencyInterface::getCacheMaxAge public function The maximum age for which this object may be cached. 34
CacheableDependencyInterface::getCacheTags public function The cache tags associated with this object. 27
ConfigurableInterface::defaultConfiguration public function Gets default configuration for this plugin. 11
ConfigurableInterface::getConfiguration public function Gets this plugin's configuration. 12
ConfigurableInterface::setConfiguration public function Sets the configuration for this plugin instance. 12
DependentPluginInterface::calculateDependencies public function Calculates dependencies for the configured plugin. 19
PanelsEverywhereDisplayVariant::$mainContent protected property The render array representing the main page content.
PanelsEverywhereDisplayVariant::$title protected property The title for the display variant.
PanelsEverywhereDisplayVariant::build public function Builds and returns the renderable array for the display variant. Overrides VariantInterface::build
PanelsEverywhereDisplayVariant::setMainContent public function Sets the main content for the page being rendered. Overrides PageVariantInterface::setMainContent
PanelsEverywhereDisplayVariant::setTitle public function Sets the title for the page being rendered. Overrides PageVariantInterface::setTitle
PluginFormInterface::buildConfigurationForm public function Form constructor. 36
PluginFormInterface::submitConfigurationForm public function Form submission handler. 32
PluginFormInterface::validateConfigurationForm public function Form validation handler. 18
PluginInspectionInterface::getPluginDefinition public function Gets the definition of the plugin implementation. 4
PluginInspectionInterface::getPluginId public function Gets the plugin_id of the plugin instance. 2
RefinableCacheableDependencyInterface::addCacheableDependency public function Adds a dependency on an object: merges its cacheability metadata. 1
RefinableCacheableDependencyInterface::addCacheContexts public function Adds cache contexts. 1
RefinableCacheableDependencyInterface::addCacheTags public function Adds cache tags. 1
RefinableCacheableDependencyInterface::mergeCacheMaxAge public function Merges the maximum age (in seconds) with the existing maximum age. 1
VariantInterface::access public function Determines if this display variant is accessible. 1
VariantInterface::adminLabel public function Returns the admin-facing display variant label. 1
VariantInterface::getWeight public function Returns the weight of the display variant. 1
VariantInterface::id public function Returns the unique ID for the display variant. 1
VariantInterface::label public function Returns the user-facing display variant label. 1
VariantInterface::setWeight public function Sets the weight of the display variant. 1