diff --git a/src/controller/AbstractDefaultController.php b/src/controller/AbstractDefaultController.php index a1e5c2d..95c5665 100644 --- a/src/controller/AbstractDefaultController.php +++ b/src/controller/AbstractDefaultController.php @@ -21,9 +21,10 @@ class AbstractDefaultController extends AbstractController private function addMenuItems(array $variables): array { if (array_key_exists('menu_items', $variables)) { - throw new \Exception('You aren\'t allowed to define this key!'); + $variables['menu_items'] = array_merge($this->getMenuItems(),$variables['menu_items']); + }else{ + $variables['menu_items'] = $this->getMenuItems(); } - $variables['menu_items'] = $this->getMenuItems(); return $variables; } diff --git a/src/controller/product/Product.php b/src/controller/product/Product.php index 8410e71..56ee5ad 100644 --- a/src/controller/product/Product.php +++ b/src/controller/product/Product.php @@ -5,6 +5,8 @@ use repository\product\Product as ProductRepository; use core\Core; use router\link\Link; use controller\AbstractDefaultController; +use Doctrine\Common\Collections\ArrayCollection; +use router\link\LinkCollection; /** * @@ -35,17 +37,18 @@ final class Product extends AbstractDefaultController implements ProductInterfac } $this->render('product/list.html.twig', [ 'products' => $products, - 'colors' => $this->getColors() + 'colors' => $this->getColors(), + 'menu_items'=>[$this->getColors()] ]); } - private function getColors(): array + private function getColors(): ArrayCollection { - $colors = []; + $colors = new LinkCollection('color filter'); foreach ($this->productRepository->getColors() as $color) { $parameters = $_GET; $parameters['color'] = $color['color']; - $colors[] = new Link($parameters, $color['color']); + $colors->add(new Link($parameters, $color['color'])); } return $colors; } diff --git a/src/router/link/LinkCollection.php b/src/router/link/LinkCollection.php new file mode 100644 index 0000000..3c4da2c --- /dev/null +++ b/src/router/link/LinkCollection.php @@ -0,0 +1,27 @@ +name = $name; + } + + public function getName(): string + { + return $this->name; + } +} + diff --git a/src/router/link/LinkCollectionInterface.php b/src/router/link/LinkCollectionInterface.php new file mode 100644 index 0000000..d2c3895 --- /dev/null +++ b/src/router/link/LinkCollectionInterface.php @@ -0,0 +1,13 @@ +
{% block content %} {% endblock %} diff --git a/src/template/frames/structure/navbar.html.twig b/src/template/frames/structure/navbar.html.twig index b0687c2..6bbe9e1 100644 --- a/src/template/frames/structure/navbar.html.twig +++ b/src/template/frames/structure/navbar.html.twig @@ -1,32 +1,34 @@ \ No newline at end of file diff --git a/src/template/product/list.html.twig b/src/template/product/list.html.twig index 349c65c..1bde3a3 100644 --- a/src/template/product/list.html.twig +++ b/src/template/product/list.html.twig @@ -1,17 +1,6 @@ {% extends 'frames/default.html.twig' %} {% block title %}product overview{% endblock %} {% block content %} - -
{% for product in products %}