You are here

public static function SettingsFormBuilder::displayForm in UI Patterns Settings 8

Same name and namespace in other branches
  1. 8.2 src/Form/SettingsFormBuilder.php \Drupal\ui_patterns_settings\Form\SettingsFormBuilder::displayForm()

Build pattern settings for display form.

Parameters

array $form: Form array.

array $configuration: Configurations array.

1 call to SettingsFormBuilder::displayForm()
ui_patterns_settings_ui_patterns_display_settings_form_alter in ./ui_patterns_settings.module
Implements hook_ui_patterns_display_form_alter().

File

src/Form/SettingsFormBuilder.php, line 55

Class

SettingsFormBuilder
Build settings in manage display form.

Namespace

Drupal\ui_patterns_settings\Form

Code

public static function displayForm(array &$form, array $configuration) {
  foreach (UiPatterns::getPatternDefinitions() as $pattern_id => $definition) {
    $settings = UiPatternsSettings::getPatternDefinitionSettings($definition);
    $form['variants'][$pattern_id]['#attributes']['class'][] = 'ui-patterns-variant-selector-' . $pattern_id;
    if (!empty($settings)) {
      foreach ($settings as $key => $setting) {
        if (empty($setting
          ->getType()) || !$setting
          ->isFormVisible()) {
          continue;
        }
        if (!isset($form['pattern_settings'][$pattern_id])) {
          $form['pattern_settings'][$pattern_id] = [
            '#type' => 'fieldset',
            '#title' => t('Settings'),
            '#states' => [
              'visible' => [
                'select[id="patterns-select"]' => [
                  'value' => $pattern_id,
                ],
              ],
            ],
          ];
        }
        $fieldset =& $form['pattern_settings'][$pattern_id];
        $settingType = UiPatternsSettings::createSettingType($setting);
        $setting_value = isset($configuration['pattern_settings'][$pattern_id][$key]) ? $configuration['pattern_settings'][$pattern_id][$key] : "";
        $fieldset += $settingType
          ->buildConfigurationForm([], $setting_value);
      }
      SettingsFormBuilder::buildVariantsForm('.ui-patterns-variant-selector-' . $pattern_id, $fieldset, $definition);
    }
  }
}