From b1cdb95b77e6ed7c42601d04649c74e63331778d Mon Sep 17 00:00:00 2001 From: Mark Woynarski Date: Thu, 14 May 2020 11:02:34 -0600 Subject: [PATCH] Allow NodeMenuItem to be overridden without replacing the whole of NodeMenu --- src/Kunstmaan/NodeBundle/Helper/NodeMenu.php | 22 +++- .../NodeBundle/Helper/NodeMenuItem.php | 14 +- .../Helper/NodeMenuItemInterface.php | 120 ++++++++++++++++++ 3 files changed, 144 insertions(+), 12 deletions(-) create mode 100644 src/Kunstmaan/NodeBundle/Helper/NodeMenuItemInterface.php diff --git a/src/Kunstmaan/NodeBundle/Helper/NodeMenu.php b/src/Kunstmaan/NodeBundle/Helper/NodeMenu.php index 020a7fbdf0..283021f011 100644 --- a/src/Kunstmaan/NodeBundle/Helper/NodeMenu.php +++ b/src/Kunstmaan/NodeBundle/Helper/NodeMenu.php @@ -112,6 +112,18 @@ public function __construct( $this->domainConfiguration = $domainConfiguration; } + /** + * @param Node $node + * @param NodeTranslation $nodeTranslation + * @param bool $parent + * @param NodeMenu $menu + * @return NodeMenuItemInterface + */ + protected function createMenuItem(Node $node, NodeTranslation $nodeTranslation, $parent = false, NodeMenu $menu) + { + return new NodeMenuItem($node, $nodeTranslation, $parent, $menu); + } + /** * @param string $locale */ @@ -257,7 +269,7 @@ public function getBreadCrumb() $this->includeOffline ); if (!\is_null($nodeTranslation)) { - $nodeMenuItem = new NodeMenuItem( + $nodeMenuItem = $this->createMenuItem( $parentNode, $nodeTranslation, $parentNodeMenuItem, @@ -321,7 +333,7 @@ public function getChildren(Node $node, $includeHiddenFromNav = true) $this->includeOffline ); if (!\is_null($nodeTranslation)) { - $children[] = new NodeMenuItem( + $children[] = $this->createMenuItem( $childNode, $nodeTranslation, false, @@ -536,7 +548,7 @@ function (Node $entry) use ($includeOffline) { $includeOffline ); if (!\is_null($nodeTranslation)) { - return new NodeMenuItem( + return $this->createMenuItem( $resultNode, $nodeTranslation, false, @@ -560,7 +572,7 @@ public function getRootNodeMenuItem() $this->locale, $this->includeOffline ); - $this->rootNodeMenuItem = new NodeMenuItem( + $this->rootNodeMenuItem = $this->createMenuItem( $rootNode, $nodeTranslation, false, @@ -679,7 +691,7 @@ private function getTopNodeMenuItems() $this->includeOffline ); if (!\is_null($nodeTranslation)) { - $topNodeMenuItems[] = new NodeMenuItem( + $topNodeMenuItems[] = $this->createMenuItem( $topNode, $nodeTranslation, null, diff --git a/src/Kunstmaan/NodeBundle/Helper/NodeMenuItem.php b/src/Kunstmaan/NodeBundle/Helper/NodeMenuItem.php index b6dff715a0..50c1098893 100644 --- a/src/Kunstmaan/NodeBundle/Helper/NodeMenuItem.php +++ b/src/Kunstmaan/NodeBundle/Helper/NodeMenuItem.php @@ -10,37 +10,37 @@ /** * NodeMenuItem */ -class NodeMenuItem +class NodeMenuItem implements NodeMenuItemInterface { /** * @var EntityManager */ - private $em; + protected $em; /** * @var Node */ - private $node; + protected $node; /** * @var NodeTranslation */ - private $nodeTranslation; + protected $nodeTranslation; /** * @var NodeMenuItem[] */ - private $children; + protected $children; /** * @var NodeMenuItem */ - private $parent; + protected $parent; /** * @var NodeMenu */ - private $menu; + protected $menu; /** * @param Node $node The node diff --git a/src/Kunstmaan/NodeBundle/Helper/NodeMenuItemInterface.php b/src/Kunstmaan/NodeBundle/Helper/NodeMenuItemInterface.php new file mode 100644 index 0000000000..96a2328f17 --- /dev/null +++ b/src/Kunstmaan/NodeBundle/Helper/NodeMenuItemInterface.php @@ -0,0 +1,120 @@ +