Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NodeBundle] Allow NodeMenuItem to be extended #2677

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 18 additions & 5 deletions src/Kunstmaan/NodeBundle/Helper/NodeMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,19 @@ 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 +270,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 +334,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 +549,7 @@ function (Node $entry) use ($includeOffline) {
$includeOffline
);
if (!\is_null($nodeTranslation)) {
return new NodeMenuItem(
return $this->createMenuItem(
$resultNode,
$nodeTranslation,
false,
Expand All @@ -560,7 +573,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 +692,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
110 changes: 110 additions & 0 deletions src/Kunstmaan/NodeBundle/Helper/NodeMenuItemInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?php

namespace Kunstmaan\NodeBundle\Helper;

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

interface NodeMenuItemInterface
{
/**
* @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();
}