コード例 #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);
 }
コード例 #2
0
ファイル: AdminForm.php プロジェクト: symforce/symforce-admin
 public function buildFormElement(\Symfony\Bundle\FrameworkBundle\Controller\Controller $controller, \Symfony\Component\Form\FormBuilder $builder, \Symforce\AdminBundle\Compiler\Cache\AdminCache $admin, \Symforce\AdminBundle\Compiler\Cache\ActionCache $action, $object, $property_name, $parent_property)
 {
     if ($object) {
         if (!$object instanceof $admin->class_name) {
             throw new \Exception();
         }
         if ($admin->workflow) {
             if ($admin !== $this) {
                 throw new \Exception();
             }
             $status = $admin->getObjectWorkflowStatus($object);
             if (!isset($status['properties'][$property_name])) {
                 return;
             }
             $flag = $status['properties'][$property_name];
             $readable = \Symforce\AdminBundle\Compiler\MetaType\Admin\Workflow::FLAG_VIEW & $flag;
             $editable = \Symforce\AdminBundle\Compiler\MetaType\Admin\Workflow::FLAG_EDIT & $flag;
             if (\Symforce\AdminBundle\Compiler\MetaType\Admin\Workflow::FLAG_AUTH & $flag) {
                 if ($readable || $editable) {
                     throw new \Exception();
                 }
                 $securityContext = $this->container->get('security.context');
                 $user = $securityContext->getToken()->getUser();
                 $group = $user->getUserGroup();
                 if ($group) {
                     $flag = $group->getWorkflowPropertyVisiable($this->name, $property_name, $status['name']);
                     if ('1' === $flag) {
                         $editable = true;
                     } else {
                         if ('2' === $flag) {
                             $readable = true;
                         }
                     }
                 }
             }
             if ($readable) {
                 $options = array();
                 $_options = $admin->getFormBuilderOption($property_name, $action, $object);
                 if ($_options) {
                     $options['label'] = $_options['label'];
                 }
                 $builder->add($property_name, 'sf_view', $options);
                 return;
             }
             if (!$editable) {
                 return;
             }
         }
     }
     $options = $admin->getFormBuilderOption($property_name, $action, $object);
     $type = $options['sf_form_type'];
     if (isset($options['read_only']) && $options['read_only']) {
         if (in_array($type, array('sf_owner', 'sf_entity', 'sf_workflow', 'choice', 'checkbox', 'sf_file', 'sf_image', 'sf_html', 'money'))) {
             $options = array();
             $_options = $admin->getFormBuilderOption($property_name, $action, $object);
             if ($_options) {
                 $options['label'] = $_options['label'];
             }
             $builder->add($property_name, 'sf_view', $options);
             return;
         }
     }
     if (isset($options['required']) && $options['required']) {
         if (!isset($options['constraints'])) {
             $options['constraints'] = array(new \Symfony\Component\Validator\Constraints\NotBlank());
         } else {
             $find_not_blank = false;
             foreach ($options['constraints'] as $_constraint) {
                 if ($_constraint instanceof \Symfony\Component\Validator\Constraints\NotBlank) {
                     $find_not_blank = true;
                 }
             }
             if (!$find_not_blank) {
                 $options['constraints'][] = new \Symfony\Component\Validator\Constraints\NotBlank();
             }
         }
     }
     /**
      * @FIXME since symfony 2.7, without this hack radio(value=0) will not get checked
      */
     if ('bool' == $options['sf_form_meta']) {
         if ($object) {
             $options['data'] = $admin->getReflectionProperty($property_name)->getValue($object) ? 1 : 0;
         } else {
             $options['data'] = 0;
         }
     }
     $this->adjustFormOptions($object, $property_name, $options);
     $subscribers = null;
     if (isset($options['subscribers'])) {
         $subscribers = $options['subscribers'];
         unset($options['subscribers']);
     }
     $builder->add($property_name, $type, $options);
     if ($subscribers) {
         $_builder = $builder->get($property_name);
         foreach ($subscribers as $subscriber) {
             $events = $subscriber->getSubscribedEvents();
             foreach ($events as $_event => $method) {
                 $_builder->addEventListener($_event, array($subscriber, $method));
             }
         }
     }
 }