public static function SettingsFormBuilder::displayForm in UI Patterns Settings 8.2
Same name and namespace in other branches
- 8 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 100
Class
- SettingsFormBuilder
- Build settings in manage display form.
Namespace
Drupal\ui_patterns_settings\FormCode
public static function displayForm(array &$form, array $configuration) {
$form['#attached']['library'][] = 'ui_patterns_settings/widget';
self::buildTokenLink($form);
foreach (UiPatterns::getPatternDefinitions() as $pattern_id => $definition) {
$settings = UiPatternsSettings::getPatternDefinitionSettings($definition);
$form['variants'][$pattern_id]['#attributes']['class'][] = 'ui-patterns-variant-selector-' . $pattern_id;
if (UiPatternsSettingsManager::allowVariantToken($definition)) {
$variant_token_value = isset($configuration['variants_token'][$pattern_id]) ? $configuration['variants_token'][$pattern_id] : NULL;
$form['variants']['#weight'] = 20;
$form['pattern_mapping']['#weight'] = 30;
$form['pattern_settings']['#weight'] = 40;
$form['variants_token'] = [
'#type' => 'container',
'#title' => t('Pattern Variant'),
'#weight' => 25,
'#states' => [
'visible' => [
'select[id="patterns-select"]' => [
'value' => $pattern_id,
],
],
],
];
$form['variants_token'][$pattern_id] = [
'#type' => 'textfield',
'#title' => t('Variant token'),
'#default_value' => $variant_token_value,
'#attributes' => [
'class' => [
'js-ui-patterns-settings-show-token-link',
],
],
'#states' => [
'visible' => [
'select[id="patterns-select"]' => [
'value' => $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($definition, $setting);
$setting_value = isset($configuration['pattern_settings'][$pattern_id][$key]) ? $configuration['pattern_settings'][$pattern_id][$key] : NULL;
$token_value = isset($configuration['pattern_settings'][$pattern_id][$key . "_token"]) ? $configuration['pattern_settings'][$pattern_id][$key . "_token"] : NULL;
$fieldset += $settingType
->buildConfigurationForm([], $setting_value, $token_value, 'display');
}
SettingsFormBuilder::buildVariantsForm('.ui-patterns-variant-selector-' . $pattern_id, $fieldset, $definition);
}
}
}