/** * @covers ::load */ public function testLoad() { // Make sure that the contexts are passed down (or not). $this->pageVariant->getContexts()->willReturn([]); $this->panelsDisplay->setContexts([])->shouldBeCalledTimes(1); $this->storage->load('id_exists')->willReturn($this->pageVariant->reveal()); $this->storage->load('doesnt_exist')->willReturn(NULL); $this->storage->load('not_a_panel')->willReturn($this->pageVariantNotPanels->reveal()); $panels_storage = new PageManagerPanelsStorage([], '', [], $this->entityTypeManager->reveal()); // Test the success condition. $this->assertSame($this->panelsDisplay->reveal(), $panels_storage->load('id_exists')); // Should be NULL if it doesn't exist. $this->assertNull($panels_storage->load('doesnt_exist')); // Should also be NULL if it's not a PanelsDisplayVariant. $this->assertNull($panels_storage->load('not_a_panel')); }
/** * Build the render array for a single panelized entity. * * @param \Drupal\Core\Entity\EntityInterface $entity * @param \Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant $panels_display * @param string $view_mode * @param string $langcode * * @return array */ protected function buildPanelized(EntityInterface $entity, PanelsDisplayVariant $panels_display, $view_mode, $langcode) { $contexts = $panels_display->getContexts(); $entity_context = new Context(new ContextDefinition('entity:' . $this->entityTypeId, NULL, TRUE), $entity); $contexts['@panelizer.entity_context:' . $this->entityTypeId] = $entity_context; $panels_display->setContexts($contexts); $build = $panels_display->build(); // @todo: I'm sure more is necessary to get the cache contexts right... CacheableMetadata::createFromObject($entity)->applyTo($build); $this->getPanelizerPlugin()->alterBuild($build, $entity, $panels_display, $view_mode); return $build; }