public function getLabel() { if (!$this->label || !$this->label instanceof \Symforce\AdminBundle\Compiler\Generator\TransGeneratorValue) { if (!$this->label) { $this->label = $this->generator->humanize(basename(str_replace('\\', '/', $this->class_name))); } if (!$this->tr_node) { $this->tr_node = $this->generator->getTransNodeByPath($this->tr_domain, $this->name); } $this->label = $this->tr_node->createValue('label', $this->label); } return $this->label; }
public function buildMenuTree(\Symforce\AdminBundle\Compiler\Generator $gen, array &$menu_config) { $list = array('root' => new Menu('root')); $tr = $gen->getTransNodeByPath($gen->sf_domain, 'sf.menu'); foreach ($menu_config['groups'] as $name => $attr) { $_menu = new Menu($name); if (false !== $attr['position']) { $_menu->setPosition($attr['position']); } if ($attr['label']) { $tr->set($name, $attr['label']); } $_menu->setLabel('sf.menu.' . $name); $_menu->setDomain($gen->sf_domain); if (false !== $attr['route']) { $_menu->setRouteName($attr['route']); } if (false !== $attr['url']) { $_menu->setUrl($attr['url']); } if (isset($attr['divider'])) { $_menu->setDivider($attr['divider']); } if (isset($attr['icon'])) { $_menu->setIcon($attr['icon']); } $list[$name] = $_menu; $parent_name = $attr['parent']; if (!isset($list[$parent_name])) { $_parent = new Menu($parent_name); $list[$parent_name] = $_parent; } $list[$parent_name]->addChild($_menu); } foreach ($gen->admin_generators as $object) { if ($object instanceof \Symforce\AdminBundle\Compiler\MetaType\Admin\Entity) { /** * @var \Symforce\AdminBundle\Compiler\MetaType\Entity */ $menu = $object->menu; if (!$menu) { continue; } if ($menu instanceof \Symforce\AdminBundle\Compiler\MetaType\Admin\Menu) { $name = $object->name; $tr = $object->tr_node; if (isset($list[$name])) { $_menu = $list[$name]; } else { $_menu = new Menu($name); $list[$name] = $_menu; } if (null !== $menu->divider) { $_menu->setDivider($menu->divider); } if (null !== $menu->label) { $tr->set('menu', $menu->label); $_menu->setLabel($name . '.menu'); } else { $_menu->setLabel($name . '.label'); } $_menu->setDomain($object->tr_domain); if (null !== $menu->icon) { $_menu->setIcon($menu->icon); } else { if (null !== $object->icon) { $_menu->setIcon($object->icon); } } if (null !== $menu->position) { $_menu->setPosition($menu->position); } $_menu->admin = true; $_parent_name = $menu->group; if (true === $_parent_name) { continue; $_parent_name = $gen->getEntityByName($name)->getParent()->getName(); } if (isset($list[$_parent_name])) { $_parent = $list[$_parent_name]; } else { $_parent = new Menu($_parent_name); $list[$_parent_name] = $_parent; } $_parent->addChild($_menu); } else { echo __FILE__, ':', __LINE__, "\n"; exit; } } else { echo __FILE__, ':', __LINE__, "\n"; exit; } } /* check associated */ foreach ($list as $name => $menu) { if (!$menu->admin) { continue; } if (!$menu->getParent()) { continue; } if (!$menu->getParent()->admin) { continue; } continue; $_entity = $this->getAdminByName($name); if ($_entity->getParent()->getName() != $menu->getParent()->getName()) { $_entity->throwError("memu group(%s) is not associated parent `%s`", $menu->getParent()->getName(), $_entity->getPureObject()->getParent()->getName()); } } return $list['root']; }
public function buildDashboardGroups(\Symforce\AdminBundle\Compiler\Generator $gen, array &$dashboard_config) { $default_group_name = $dashboard_config['default_group']; $groups = array(); $tr = $gen->getTransNodeByPath($gen->sf_domain, 'sf.dashboard'); foreach ($dashboard_config['groups'] as $name => $attr) { if (isset($groups[$name])) { $_item = $groups[$name]; } else { $_item = new CacheObject\DashboardGroup($name); $groups[$name] = $_item; } if (false !== $attr['position']) { $_item->setPosition($attr['position']); } if ($attr['label']) { $tr->set($name, $attr['label']); } $_item->setLabel('sf.dashboard.' . $name); if (isset($attr['icon'])) { $_item->setIcon($attr['icon']); } if (isset($attr['right_side'])) { $_item->setRightSide($attr['right_side']); } } foreach ($gen->admin_generators as $object) { if ($object instanceof \Symforce\AdminBundle\Compiler\MetaType\Admin\Entity) { $item = $object->dashboard; if (!$item) { continue; } if ($item instanceof \Symforce\AdminBundle\Compiler\MetaType\Admin\Dashboard) { $tr = $object->tr_node; $group_name = $item->group; if (!$group_name) { continue; } if (true === $group_name) { $group_name = $default_group_name; } if (!isset($groups[$group_name])) { $group = new CacheObject\DashboardGroup($group_name); $groups[$group_name] = $group; } else { $group = $groups[$group_name]; } $_item = new CacheObject\DashboardItem($object->name); $_item->setDomain($object->tr_domain); if (null !== $item->label) { $_item->setLabel($object->name . '.dashboard'); $tr->set('dashboard', $item->label); } else { $_item->setLabel($object->name . '.label'); } if (null !== $item->icon) { $_item->setIcon($item->icon); } else { if (null !== $object->icon) { $_item->setIcon($object->icon); } } if (null !== $item->position) { $_item->setPosition($item->position); } $_item->setEntity(true); $group->addChild($_item); // add actions foreach ($object->action_collection->children as $action) { $pos = $action->dashboard; if (!$pos) { continue; } $_action = new CacheObject\DashboardAction($action->name); $_action->setLabel($action->label->getPath()); $_action->setDomain($action->label->getDomain()); $_item->addAction($_action); } } else { echo __FILE__, ':', __LINE__, "\n"; exit; } } else { echo __FILE__, ':', __LINE__, "\n"; exit; } } foreach ($groups as $group_name => $group) { $_group = $group->children; $pos = array(); foreach ($_group as $item) { if (null !== $item->postion) { $pos[$item->postion] = true; } } $_pos = 1; foreach ($_group as $item) { if (null === $item->postion) { while (isset($pos[$_pos])) { $_pos++; } $item->postion = $_pos; } } usort($_group, array($this, 'sort_item')); $group->children = array(); foreach ($_group as $item) { $group->children[$item->name] = $item; } } return $groups; }