/**
  * Handle the command.
  *
  * @return \Anomaly\Streams\Platform\Addon\FieldType\FieldTypePresenter|mixed|object
  */
 public function handle()
 {
     /* @var FieldType $type */
     if ($type = $this->dispatch(new GetValueFieldType($this->preference))) {
         return $type->getPresenter();
     }
     return array_get($this->preference->getAttributes(), 'value');
 }
 /**
  * Handle the command.
  *
  * @param FieldTypeCollection $fieldTypes
  * @param Repository          $config
  * @return FieldType
  */
 public function handle(FieldTypeCollection $fieldTypes, Repository $config)
 {
     // Get the preference's key.
     $key = $this->preference->getKey();
     // Get the bare value.
     $value = array_get($this->preference->getAttributes(), 'value');
     // Try and find the preference's field configuration.
     if (!($field = $config->get(str_replace('::', '::preferences/preferences.', $key)))) {
         $field = $config->get(str_replace('::', '::preferences.', $key));
     }
     // Convert short syntax.
     if (is_string($field)) {
         $field = ['type' => $field];
     }
     /**
      * Try and get the field type that
      * the preference 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->preference);
     $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;
 }