/**
  * Return the form fields.
  *
  * @param PreferenceFormBuilder $builder
  */
 public function handle(PreferenceFormBuilder $builder, PreferenceRepositoryInterface $preferences)
 {
     $namespace = $builder->getEntry() . '::';
     /**
      * Get the fields from the config system. Sections are
      * optionally defined the same way.
      */
     if (!($fields = $this->config->get($namespace . 'preferences/preferences'))) {
         $fields = $fields = $this->config->get($namespace . 'preferences', []);
     }
     if ($sections = $this->config->get($namespace . 'preferences/sections')) {
         $builder->setSections($sections);
     }
     /**
      * Finish each field.
      */
     foreach ($fields as $slug => &$field) {
         /**
          * Force an array. This is done later
          * too in normalization but we need it now
          * because we are normalizing / guessing our
          * own parameters somewhat.
          */
         if (is_string($field)) {
             $field = ['type' => $field];
         }
         // Make sure we have a config property.
         $field['config'] = array_get($field, 'config', []);
         // Default the label.
         $field['label'] = array_get($field, 'label', $namespace . 'preference.' . $slug . '.label');
         // Default the placeholder.
         $field['config']['placeholder'] = array_get($field['config'], 'placeholder', $namespace . 'preference.' . $slug . '.placeholder');
         // Default the instructions.
         $field['instructions'] = array_get($field, 'instructions', $namespace . 'preference.' . $slug . '.instructions');
         // Get the value defaulting to the default value.
         if ($preference = $preferences->get($namespace . $slug)) {
             $field['value'] = $preference->getValue();
         } else {
             $field['value'] = array_get($field['config'], 'default_value');
         }
     }
     $builder->setFields($fields);
 }
 /**
  * Return a form for editing preferences.
  *
  * @param PreferenceFormBuilder $form
  * @return \Illuminate\View\View|\Symfony\Component\HttpFoundation\Response
  */
 public function edit(PreferenceFormBuilder $form)
 {
     return $form->render('streams');
 }
 /**
  * Return a form for editing preferences.
  *
  * @param PreferenceFormBuilder $form
  * @param                       $type
  * @param                       $addon
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function edit(PreferenceFormBuilder $form, $type, $addon)
 {
     unset($type);
     return $form->render($addon);
 }