You are here

public function FasttoggleSettingsForm::buildFormContent in Fasttoggle 8.2

Get the sitewide settings form content.

Parameters

array $form: The Drupal form array.

array $form_state: The Drupal form_state array.

1 call to FasttoggleSettingsForm::buildFormContent()
FasttoggleSettingsForm::buildForm in src/Form/FasttoggleSettingsForm.php
Form constructor.

File

src/Form/FasttoggleSettingsForm.php, line 76
Contains \Drupal\fasttoggle\Form\FasttoggleSettingsForm.

Class

FasttoggleSettingsForm
Configure fasttoggle settings for this site.

Namespace

Drupal\fasttoggle\Form

Code

public function buildFormContent(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('fasttoggle.settings');
  $form['label_style'] = [
    '#type' => 'radios',
    '#title' => t('Label style'),
    '#description' => t('Select what kind of labels you want for fasttoggle links. See the README.txt for information about providing your own labels.'),
    '#options' => [
      FASTTOGGLE_LABEL_STATUS => t('Status (reflects the current state, e.g. "published", "active")'),
      FASTTOGGLE_LABEL_ACTION => t('Action (shows what happens upon a click, e.g. "unpublish", "block")'),
    ],
    '#default_value' => $config
      ->get('label_style'),
  ];
  if (0) {

    // @TODO Custom labels.
    $custom_labels = $config
      ->get('custom_labels');
    if (!empty($custom_labels)) {
      $form['fasttoggle_label_style']['#options'][FASTTOGGLE_LABEL_CUSTOM] = t('Custom (configure in your settings.php)');
    }
  }

  // Get all settings, grouped by entity and setting group.
  $objects = $this->objectManager
    ->getDefinitions();
  $groups = $this->groupManager
    ->getDefinitions();
  $settings = $this->settingManager
    ->getDefinitions();
  foreach ($objects as $object => $objectDef) {
    $object_plugin = $this->objectManager
      ->createInstance($object);
    $elements_for_type = $object_plugin
      ->getSitewideSettingFormElements($config);
    foreach ($groups[$object] as $group => $groupDef) {
      $groupPlugin = $this->groupManager
        ->createInstance($group);
      foreach ($settings[$object][$group] as $setting => $settingDef) {
        if (!isset($elements_for_type[$group])) {
          if ($groupDef['title']) {
            $elements_for_type[$group] = [
              '#type' => 'fieldset',
              '#title' => $groupDef['title'],
              '#description' => $groupDef['description'],
              '#weight' => $groupDef['weight'],
            ];
            $fieldset =& $elements_for_type[$group];
          }
          else {
            $fieldset =& $elements_for_type;
          }
        }
        $setting_plugin = $this->settingManager
          ->createInstance($setting);
        $configKeys = $setting_plugin
          ->configSettingKeys();
        foreach ($configKeys as $key) {
          $fieldset[$key] = $setting_plugin
            ->settingForm($config, $key);
        }
      }
    }
    if (!empty($elements_for_type)) {
      $form[$object] = [
        '#type' => 'fieldset',
        '#title' => $objectDef['title'],
        '#description' => $objectDef['description'],
        '#weight' => $objectDef['weight'],
      ];
      $form[$object] += $elements_for_type;
    }
  }
  return parent::buildForm($form, $form_state);
}