/** * Returns the rendered breadcrumb. * * @param \Twig_Environment $twig * @param array $context Twig context containing all the view variables. * @return string */ public function renderBreadcrumb(\Twig_Environment $twig, array $context) { $breadcrumb = []; foreach ($this->builder->getItems() as $item) { $breadcrumb[] = $this->itemProcessor->process($item, $context); } return $twig->render($this->template, ['items' => $breadcrumb]); }
/** * @covers ::__construct * @covers ::addItem * @covers ::getItems */ public function test_getItems_nonEmptyBreadcrumb() { $item1 = \Mockery::mock(BreadcrumbItem::class); $this->itemFactory->shouldReceive('create')->with('aLabel', 'aRoute', null)->andReturn($item1); $item2 = \Mockery::mock(BreadcrumbItem::class); $this->itemFactory->shouldReceive('create')->with('anotherLabel', 'anotherRoute', ['a' => 'b'])->andReturn($item2); $this->builder->addItem('aLabel', 'aRoute'); $this->builder->addItem('anotherLabel', 'anotherRoute', ['a' => 'b']); $this->assertEquals([$item1, $item2], $this->builder->getItems()); }
/** * @param FilterControllerEvent $event */ public function onKernelController(FilterControllerEvent $event) { list($controller, $action) = $event->getController(); $class = new \ReflectionClass($controller); $method = new \ReflectionMethod($controller, $action); $annotations = []; if ($classAnnotation = $this->annotationReader->getClassAnnotation($class, Breadcrumb::class)) { $annotations[] = $classAnnotation; } if ($methodAnnotation = $this->annotationReader->getMethodAnnotation($method, Breadcrumb::class)) { $annotations[] = $methodAnnotation; } foreach ($annotations as $annotation) { foreach ($annotation->items as $item) { $this->breadcrumbBuilder->addItem($item['label'], isset($item['route']) ? $item['route'] : null, isset($item['params']) ? $item['params'] : null); } } }