namespace Cubist\Backpack\app\Magic\Menu;
use Cubist\Backpack\app\Magic\Models\CMSPage;
+use Cubist\Backpack\app\Magic\Models\CubistMagicPageModel;
use Cubist\Backpack\app\Magic\Models\Locale;
+use Cubist\Backpack\app\Magic\PageData;
use Cubist\Backpack\app\Template\Navigation;
+use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Str;
+use stdClass;
class Item
{
+ /** @var Item */
+ protected $_root;
+
/** @var Item */
protected $_parent;
*/
protected $_locale = '';
+ /**
+ * @var CubistMagicPageModel
+ */
+ protected $_entity;
+
/**
* @param string $id
$all = $class::orderBy('lft')->get();
$this->setId('#root');
+ $this->setRoot($this);
$this->setBreadcrumbs(false);
$this->setName($id);
$this->setChildrenFromData($all, null);
public function addChildFromData($data, $all)
{
$child = new PageItem();
+ $child->setEntity($data);
$child->setLocale($this->getLocale());
if ($data->getUsedTemplate() instanceof Navigation) {
$child->setBreadcrumbs(false);
*/
public function addChild($item)
{
- if ($item->getRawLocale() === '') {
+ $locale = $item->getRawLocale();
+ if (!$locale) {
$item->setLocale($this->getLocale());
}
$item->setParent($this);
return $this;
}
$res = Menu::getNavigation($locale)->findOneById($this->getId());
- if (!$strict && null === $res && null !== $this->getParent()) {
+ if (!$strict && null === $res) {
+ if (null === $this->getParent()) {
+ return $this->getRoot()->findOneById('home')->getTranslatedPage($locale, $strict);
+
+ }
return $this->getParent()->getTranslatedPage($locale, $strict);
}
return $res;
public function setParent(Item $parent): void
{
$this->_parent = $parent;
+ $root = $parent->getRoot();
+ if ($root !== null) {
+ $this->setRoot($root);
+ }
+ }
+
+ /**
+ * @return Item
+ */
+ public function getRoot()
+ {
+ return $this->_root;
+ }
+
+ /**
+ * @param Item $root
+ */
+ public function setRoot(Item $root): void
+ {
+ $this->_root = $root;
+ }
+
+ /**
+ * @param CubistMagicPageModel $entity
+ */
+ public function setEntity(CubistMagicPageModel $entity): void
+ {
+ $this->_entity = $entity;
+ }
+
+ /**
+ * @return CubistMagicPageModel
+ */
+ public function getEntity(): CubistMagicPageModel
+ {
+ return $this->_entity;
+ }
+
+ /**
+ * @return PageData
+ */
+ public function getPageData(){
+ return $this->getEntity()->getPageData();
}
}