Skip to content

Commit

Permalink
Allow NodeMenuItem to be overridden without replacing the whole of No…
Browse files Browse the repository at this point in the history
…deMenu
  • Loading branch information
mwoynarski committed May 14, 2020
1 parent c7681fe commit b1cdb95
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 12 deletions.
22 changes: 17 additions & 5 deletions src/Kunstmaan/NodeBundle/Helper/NodeMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -257,7 +269,7 @@ public function getBreadCrumb()
$this->includeOffline
);
if (!\is_null($nodeTranslation)) {
$nodeMenuItem = new NodeMenuItem(
$nodeMenuItem = $this->createMenuItem(
$parentNode,
$nodeTranslation,
$parentNodeMenuItem,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -536,7 +548,7 @@ function (Node $entry) use ($includeOffline) {
$includeOffline
);
if (!\is_null($nodeTranslation)) {
return new NodeMenuItem(
return $this->createMenuItem(
$resultNode,
$nodeTranslation,
false,
Expand All @@ -560,7 +572,7 @@ public function getRootNodeMenuItem()
$this->locale,
$this->includeOffline
);
$this->rootNodeMenuItem = new NodeMenuItem(
$this->rootNodeMenuItem = $this->createMenuItem(
$rootNode,
$nodeTranslation,
false,
Expand Down Expand Up @@ -679,7 +691,7 @@ private function getTopNodeMenuItems()
$this->includeOffline
);
if (!\is_null($nodeTranslation)) {
$topNodeMenuItems[] = new NodeMenuItem(
$topNodeMenuItems[] = $this->createMenuItem(
$topNode,
$nodeTranslation,
null,
Expand Down
14 changes: 7 additions & 7 deletions src/Kunstmaan/NodeBundle/Helper/NodeMenuItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
120 changes: 120 additions & 0 deletions src/Kunstmaan/NodeBundle/Helper/NodeMenuItemInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<?php


namespace Kunstmaan\NodeBundle\Helper;


use Kunstmaan\NodeBundle\Entity\HasNodeInterface;
use Kunstmaan\NodeBundle\Entity\Node;
use Kunstmaan\NodeBundle\Entity\NodeTranslation;

interface NodeMenuItemInterface
{
/**
* @param Node $node The node
* @param NodeTranslation $nodeTranslation The nodetranslation
* @param NodeMenuItem|null|false $parent The parent nodemenuitem
* @param NodeMenu $menu The menu
*/
public function __construct(Node $node, NodeTranslation $nodeTranslation, $parent = false, NodeMenu $menu);

/**
* @return int
*/
public function getId();

/**
* @return Node
*/
public function getNode();

/**
* @return NodeTranslation
*/
public function getNodeTranslation();

/**
* @return string
*/
public function getTitle();

/**
* @return bool
*/
public function getOnline();

/**
* @return string|null
*/
public function getSlugPart();

/**
* @return string
*/
public function getSlug();

/**
* @return string
*/
public function getUrl();

/**
* @return NodeMenuItem|null
*/
public function getParent();

/**
* @param NodeMenuItem|null|false $parent
*/
public function setParent($parent = false);

/**
* @param string $class
*
* @return NodeMenuItem|null
*/
public function getParentOfClass($class);

/**
* @return NodeMenuItem[]
*/
public function getParents();

/**
* @param bool $includeHiddenFromNav Include hiddenFromNav nodes
*
* @return NodeMenuItem[]
*/
public function getChildren($includeHiddenFromNav = true);

/**
* @param string $class
*
* @return NodeMenuItem[]
*/
public function getChildrenOfClass($class);

/**
* Get the first child of class, this is not using the getChildrenOfClass method for performance reasons
*
* @param string $class
*
* @return NodeMenuItem
*/
public function getChildOfClass($class);

/**
* @return HasNodeInterface
*/
public function getPage();

/**
* @return bool
*/
public function getActive();

/**
* @return string
*/
public function getLang();
}

0 comments on commit b1cdb95

Please sign in to comment.