Ejemplo n.º 1
0
 /**
  * @param Field $field
  * @param $entity
  * @param $applicationConfiguration
  * @return mixed
  */
 public function field(Field $field, $entity, ApplicationConfiguration $applicationConfiguration)
 {
     $accessor = PropertyAccess::createPropertyAccessorBuilder()->enableMagicCall()->getPropertyAccessor();
     $value = $accessor->getValue($entity, $field->getName());
     if ($value instanceof DateTime) {
         $value = $value->format($applicationConfiguration->dateFormat);
     } else {
         if (is_array($value)) {
             $value = $this->recursiveImplode(', ', $value);
         }
     }
     return $value;
 }
Ejemplo n.º 2
0
 /**
  * Create an Action from configuration values
  *
  * @param $actionName
  * @param $actionConfiguration
  * @param Admin $admin
  * @return Action
  */
 protected function createActionFromConfig($actionName, $actionConfiguration, Admin $admin)
 {
     $resolver = new OptionsResolver();
     $resolver->setDefaults($this->getDefaultActionConfiguration($actionName));
     $actionConfiguration = $resolver->resolve($actionConfiguration);
     // guess title if not provided
     if (!$actionConfiguration['title']) {
         $actionConfiguration['title'] = $this->getDefaultActionTitle($admin->getName(), $actionName);
     }
     $action = new Action();
     $action->setName($actionName);
     $action->setTitle($actionConfiguration['title']);
     $action->setPermissions($actionConfiguration['permissions']);
     $action->setRoute($admin->generateRouteName($action->getName()));
     $action->setExport($actionConfiguration['export']);
     // adding fields items to actions
     foreach ($actionConfiguration['fields'] as $fieldName => $fieldConfiguration) {
         $field = new Field();
         $field->setName($fieldName);
         $field->setTitle($this->inflectString($fieldName));
         if (array_key_exists('length', $fieldConfiguration)) {
             $field->setLength($fieldConfiguration['length']);
         }
         $action->addField($field);
     }
     return $action;
 }