$path = 'home';
}
$nav = Menu::getNavigation();
- $item = $nav->findItemByHref($path);
+ $item = $nav->findOneByHref($path);
if (null === $item) {
$this->_404();
}
$this->addChild($child);
}
-
- public function findItemByHref($href)
+ /**
+ * @param $param
+ * @param $search
+ * @return $this|Item|null
+ */
+ public function findOneBy($param, $search)
{
- if ($this->getHref() == $href) {
+ if ($this->get($param) == $search) {
return $this;
}
if (!$this->hasChildren()) {
return null;
}
foreach ($this->getChildren() as $child) {
- $res = $child->findItemByHref($href);
+ $res = $child->findOneBy($param, $search);
if (null !== $res) {
return $res;
}
return null;
}
+ public function get($param)
+ {
+ $name = 'get' . ucfirst($param);
+ if (method_exists($this, $name)) {
+ return $this->$name();
+ }
+ return null;
+ }
+
+ /**
+ * @param $id
+ * @return Item|null
+ */
+ public function findOneById($id)
+ {
+ return $this->findOneBy('id', $id);
+ }
+
+ /**
+ * @param $href
+ * @return Item|null
+ */
+ public function findOneByHref($href)
+ {
+ return $this->findOneBy('href', $href);
+ }
+
/**
* @return string
*/
public function getHref()
{
- if ($this->getPage()->isRedirection()) {
- if ($this->getPage()->template == 'FirstRedirection' && $this->hasChildren()) {
- return $this->getChildren()[0]->getHref();
- } else if ($this->getPage()->template == 'InternalRedirection') {
- } else if ($this->getPage()->template == 'Redirection') {
- return $this->navigation;
- }
+ if ($this->getPage()->template == 'first_redirection' && $this->hasChildren()) {
+ return $this->getChildren()[0]->getHref();
+ } else if ($this->getPage()->template == 'internal_redirection') {
+ } else if ($this->getPage()->template == 'redirection') {
+ return $this->navigation;
}
if ($this->getPage()->getUsedTemplate()->isVirtual()) {
return Json::decodeRecursive(parent::_prepareData($attributes), Json::TYPE_ARRAY);
}
- /**
- * @return bool
- */
- public function isRedirection()
- {
- return $this->_usedTemplate instanceof Redirection;
- }
-
public static function getPageClass()
{
$class = CMSPage::class;