You are here

class SalvattoreAdminSettingsForm in Salvattore (CSS driven Masonry) 8

Same name in this branch
  1. 8 src/SalvattoreAdminSettingsForm.php \Drupal\salvattore\SalvattoreAdminSettingsForm
  2. 8 src/Form/SalvattoreAdminSettingsForm.php \Drupal\salvattore\Form\SalvattoreAdminSettingsForm

Hierarchy

Expanded class hierarchy of SalvattoreAdminSettingsForm

File

src/SalvattoreAdminSettingsForm.php, line 4

Namespace

Drupal\salvattore
View source
class SalvattoreAdminSettingsForm extends ConfigFormBase {

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'salvattore_admin_settings_form';
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $config = $this
      ->config('salvattore.settings');
    foreach (Element::children($form) as $variable) {
      $config
        ->set($variable, $form_state
        ->getValue($form[$variable]['#parents']));
    }
    $config
      ->save();
    if (method_exists($this, '_submitForm')) {
      $this
        ->_submitForm($form, $form_state);
    }
    parent::submitForm($form, $form_state);
  }

  /**
   * {@inheritdoc}
   */
  protected function getEditableConfigNames() {
    return [
      'salvattore.settings',
    ];
  }
  public function buildForm(array $form, \Drupal\Core\Form\FormStateInterface $form_state) {
    $form = [];
    $form['salvattore_use_min_js'] = [
      '#title' => t('Javascript file to use'),
      '#description' => t('Please choose whether you want the minified or the full version of the JS file.'),
      '#type' => 'radios',
      '#options' => [
        '1' => 'Minified',
        '0' => 'Full (debug)',
      ],
      '#default_value' => \Drupal::config('salvattore.settings')
        ->get('salvattore_use_min_js'),
    ];
    $form['salvattore_load_default_css'] = [
      '#title' => t('Load default CSS'),
      '#description' => t('Salvattore is easily configurable via CSS and you should write your own in your theme.<br>If some reason you want to use the default then enable this setting.'),
      '#type' => 'checkbox',
      '#default_value' => \Drupal::config('salvattore.settings')
        ->get('salvattore_load_default_css'),
    ];
    return parent::buildForm($form, $form_state);
  }

}

Members