You are here

public function PageManagerSectionStorage::getContextsDuringPreview in Page Manager 8.4

Gets contexts for use during preview.

When not in preview, ::getContexts() will be used.

Return value

\Drupal\Core\Plugin\Context\ContextInterface[] The plugin contexts suitable for previewing.

Overrides SectionStorageBase::getContextsDuringPreview

File

src/Plugin/SectionStorage/PageManagerSectionStorage.php, line 249

Class

PageManagerSectionStorage
Defines the 'page_manager' section storage type.

Namespace

Drupal\page_manager\Plugin\SectionStorage

Code

public function getContextsDuringPreview() {
  $contexts = $this
    ->getPageVariant()
    ->getContexts() + $this
    ->getPageVariant()
    ->getStaticContexts();
  foreach ($contexts as $name => $context) {
    if (!$context
      ->hasContextValue()) {
      $data_type = $context
        ->getContextDefinition()
        ->getDataType();
      if (strpos($data_type, 'entity:') === 0) {
        list(, $entity_type_id) = explode(':', $data_type, 2);
        $bundle = $entity_type_id;
        if ($this->entityTypeManager
          ->getDefinition($entity_type_id)
          ->hasKey('bundle')) {
          $bundle = key($this->entityTypeBundleInfo
            ->getBundleInfo($entity_type_id));
        }
        $sample = $this->sampleEntityGenerator
          ->get($entity_type_id, $bundle);
        $contexts[$name] = Context::createFromContext($context, $sample);
      }
    }
  }
  return $contexts;
}