示例#1
0
 public function path($object = null, $options = array())
 {
     if ($object && !$object instanceof $this->admin_class) {
         if (!$this->admin->tree || 0 !== $object) {
             throw new \Exception(sprintf("expect `%s`, get `%s` ", $this->admin->getClassName(), is_object($object) ? get_class($object) : gettext($object)));
         }
     }
     if (null === $object) {
         if ($this->isRequestObject()) {
             $object = $this->admin->getRouteObject();
         } else {
             if ($this->admin->tree && $this->admin->getTreeObjectId()) {
                 $object = $this->admin->getTreeObject();
             }
         }
     }
     if ($this->admin->tree) {
         if ($this->isRequestObject()) {
             $parent = $this->admin->getReflectionProperty($this->admin->tree['parent'])->getValue($object);
             if ($parent) {
                 $options['sf_admin_tree_parent'] = $this->admin->getReflectionProperty($this->admin->getPropertyIdName())->getValue($parent);
             } else {
                 $options['sf_admin_tree_parent'] = 0;
             }
             // todo check if it match $this->admin->getTreeObjectId(
         } else {
             if ($object) {
                 $options['sf_admin_tree_parent'] = $this->admin->getReflectionProperty($this->admin->getPropertyIdName())->getValue($object);
             } else {
                 if (0 === $object) {
                     $options['sf_admin_tree_parent'] = 0;
                 } else {
                     $options['sf_admin_tree_parent'] = $this->admin->getTreeObjectId();
                 }
             }
         }
     }
     if ($this->admin->workflow) {
         if (!isset($options['admin_route_workflow'])) {
             $options['admin_route_workflow'] = $this->admin->getRouteWorkflow();
             if (!$options['admin_route_workflow']) {
                 unset($options['admin_route_workflow']);
             }
         }
     }
     if ($this->isRequestObject()) {
         return $this->admin_loader->generateRoutePathWithObject($this->getAdminRouteName(), $object, $options);
     }
     return $this->admin_loader->generateRoutePathWithoutObject($this->getAdminRouteName(), $options);
 }