/**
  * Build a field type.
  *
  * @param array $parameters
  * @return FieldType
  */
 public function build(array $parameters)
 {
     $type = array_get($parameters, 'type');
     /**
      * If the field type is a string and
      * starts with the root namespace for
      * streams then it's a class path and
      * we can resolve it from the container.
      */
     if (is_string($type) && starts_with($type, 'Anomaly') && class_exists($type)) {
         $type = clone $this->container->make($type);
     }
     /**
      * If the field type is a dot format
      * namespace then we can also resolve
      * the field type from the container.
      */
     if (is_string($type) && str_is('*.*.*', $type)) {
         $type = $this->fieldTypes->get($type);
     }
     /**
      * If we have gotten this far then it's
      * likely a simple slug and we can try
      * returning the first match for the slug.
      */
     if (is_string($type)) {
         $type = $this->fieldTypes->findBySlug($type);
     }
     /**
      * If we don't have a field type let em know.
      */
     if (!$type) {
         throw new \Exception("Field type [{$type}] not found.");
     }
     $type->mergeRules(array_pull($parameters, 'rules', []));
     $type->mergeConfig(array_pull($parameters, 'config', []));
     $this->hydrator->hydrate($type, $parameters);
     return $type;
 }
 /**
  * Handle the command.
  *
  * @param FieldTypeCollection $fieldTypes
  * @param Repository          $config
  * @return FieldType
  */
 public function handle(FieldTypeCollection $fieldTypes, Repository $config)
 {
     // Get the configuration's key.
     $key = $this->configuration->getKey();
     // Get the bare value.
     $value = array_get($this->configuration->getAttributes(), 'value');
     // Try and find the configuration's field configuration.
     if (!($field = $config->get(str_replace('::', '::configuration/configuration.', $key)))) {
         $field = $config->get(str_replace('::', '::configuration.', $key));
     }
     // Convert short syntax.
     if (is_string($field)) {
         $field = ['type' => $field];
     }
     /**
      * Try and get the field type that
      * the configuration uses. If none exists
      * then just return the value as is.
      */
     $type = $fieldTypes->get(array_get($field, 'type'));
     if (!$type) {
         return null;
     }
     // Setup the field type.
     $type->setEntry($this->configuration);
     $type->mergeRules(array_get($field, 'rules', []));
     $type->mergeConfig(array_get($field, 'config', []));
     /**
      * If the type can be determined then
      * get the modifier and restore the value
      * before returning it.
      */
     $modifier = $type->getModifier();
     $type->setValue($modifier->restore($value));
     return $type;
 }
 /**
  * Return the form for a new field.
  *
  * @param FieldFormBuilder          $form
  * @param StreamRepositoryInterface $streams
  * @param FieldTypeCollection       $fieldTypes
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function create(FieldFormBuilder $form, StreamRepositoryInterface $streams, FieldTypeCollection $fieldTypes)
 {
     $form->setStream($streams->findBySlugAndNamespace('posts', 'posts'))->setFieldType($fieldTypes->get($_GET['field_type']));
     return $form->render();
 }
 /**
  * Return the modal for choosing a field type.
  *
  * @param FieldTypeCollection $fieldTypes
  * @return \Illuminate\View\View
  */
 public function chooseFieldType(FieldTypeCollection $fieldTypes)
 {
     $url = $_SERVER['HTTP_REFERER'];
     return view('module::ajax/choose_field_type', ['field_types' => $fieldTypes->all(), 'url' => $url]);
 }
 /**
  * Return the form for a new field.
  *
  * @param FieldFormBuilder    $form
  * @param FieldTypeCollection $fieldTypes
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function create(FieldFormBuilder $form, FieldTypeCollection $fieldTypes)
 {
     $form->setNamespace('variables')->setFieldType($fieldTypes->get($_GET['field_type']));
     return $form->render();
 }
 /**
  * Return the modal for choosing a field type.
  *
  * @param FieldTypeCollection $fieldTypes
  * @return \Illuminate\View\View
  */
 public function choose(FieldTypeCollection $fieldTypes)
 {
     return view('module::ajax/choose_field_type', ['field_types' => $fieldTypes->all()]);
 }
 /**
  * Return the form for a new field.
  *
  * @param FieldFormBuilder    $form
  * @param UserModel           $users
  * @param FieldTypeCollection $fieldTypes
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function create(FieldFormBuilder $form, UserModel $users, FieldTypeCollection $fieldTypes)
 {
     $form->setStream($users->getStream())->setOption('auto_assign', true)->setFieldType($fieldTypes->get($_GET['field_type']));
     return $form->render();
 }