/** * @covers ::getContexts */ public function testGetContexts() { $context = new Context(new ContextDefinition('bar')); $event_dispatcher = $this->prophesize(EventDispatcherInterface::class); $event_dispatcher->dispatch(PageManagerEvents::PAGE_CONTEXT, Argument::type(PageManagerContextEvent::class))->will(function ($args) use($context) { $args[1]->getPageExecutable()->addContext('foo', $context); }); $container = new ContainerBuilder(); $container->set('event_dispatcher', $event_dispatcher->reveal()); \Drupal::setContainer($container); $contexts = $this->exectuable->getContexts(); $this->assertSame(['foo' => $context], $contexts); }
/** * {@inheritdoc} */ public function getContexts() { // In the form, we have the page executable assigned directly. if ($this->page) { return $this->page->getContexts(); } // If we are on a page manager page, return the available context. if (\Drupal::request()->attributes->has('page_manager_page')) { return \Drupal::request()->attributes->get('page_manager_page')->getContexts(); } return (array) parent::getContexts(); }
/** * Returns available context as token data. * * @return array * An array with token data values keyed by token type. */ protected function getContextAsTokenData() { $data = []; foreach ($this->executable->getContexts() as $context) { // @todo Simplify this when token and typed data types are unified in // https://drupal.org/node/2163027. if (strpos($context->getContextDefinition()->getDataType(), 'entity:') === 0) { $token_type = substr($context->getContextDefinition()->getDataType(), 7); if ($token_type == 'taxonomy_term') { $token_type = 'term'; } $data[$token_type] = $context->getContextValue(); } } return $data; }
public function getContexts() { return $this->executable->getContexts(); }