setInPreview example


  public function __construct(SectionComponent $component, array $contexts$in_preview = FALSE) {
    $this->component = $component;
    $this->contexts = $contexts;
    $this->plugin = $component->getPlugin($contexts);
    $this->inPreview = $in_preview;

    if ($this->plugin instanceof PreviewAwarePluginInterface) {
      $this->plugin->setInPreview($in_preview);
    }
  }

  /** * Get the section component whose render array is being built. * * @return \Drupal\layout_builder\SectionComponent * The section component whose render array is being built. */
  public function getComponent() {
    return $this->component;
  }

  public function toRenderArray(array $contexts = []$in_preview = FALSE) {
    $regions = [];
    foreach ($this->getComponents() as $component) {
      if ($output = $component->toRenderArray($contexts$in_preview)) {
        $regions[$component->getRegion()][$component->getUuid()] = $output;
      }
    }

    $layout = $this->getLayout($contexts);
    if ($layout instanceof PreviewAwarePluginInterface) {
      $layout->setInPreview($in_preview);
    }

    $build = $layout->build($regions);
    // If an entity was used to build the layout, store it on the build.     if (!Element::isEmpty($build) && isset($contexts['layout_builder.entity'])) {
      $build['#entity'] = $contexts['layout_builder.entity']->getContextValue();
    }
    return $build;
  }

  /** * Gets the layout plugin for this section. * * @param \Drupal\Core\Plugin\Context\ContextInterface[] $contexts * An array of available contexts. * * @return \Drupal\Core\Layout\LayoutInterface * The layout plugin. */
Home | Imprint | This part of the site doesn't use cookies.