function FieldGroupAddForm::buildFormatterSelectionForm in Field Group 8
Same name and namespace in other branches
- 8.3 src/Form/FieldGroupAddForm.php \Drupal\field_group\Form\FieldGroupAddForm::buildFormatterSelectionForm()
Build the formatter selection step.
1 call to FieldGroupAddForm::buildFormatterSelectionForm()
- FieldGroupAddForm::buildForm in src/
Form/ FieldGroupAddForm.php - Form constructor.
File
- src/
Form/ FieldGroupAddForm.php, line 112
Class
- FieldGroupAddForm
- Provides a form for adding a fieldgroup to a bundle.
Namespace
Drupal\field_group\FormCode
function buildFormatterSelectionForm(array &$form, FormStateInterface $form_state) {
// Gather group formatters.
$formatter_options = \field_group_field_formatter_options($form_state
->get('context'));
$form['add'] = array(
'#type' => 'container',
'#attributes' => array(
'class' => array(
'form--inline',
'clearfix',
),
),
);
$form['add']['group_formatter'] = array(
'#type' => 'select',
'#title' => $this
->t('Add a new group'),
'#options' => $formatter_options,
'#empty_option' => $this
->t('- Select a group type -'),
'#required' => TRUE,
);
// Field label and field_name.
$form['new_group_wrapper'] = array(
'#type' => 'container',
'#states' => array(
'!visible' => array(
':input[name="group_formatter"]' => array(
'value' => '',
),
),
),
);
$form['new_group_wrapper']['label'] = array(
'#type' => 'textfield',
'#title' => $this
->t('Label'),
'#size' => 15,
'#required' => TRUE,
);
$form['new_group_wrapper']['group_name'] = array(
'#type' => 'machine_name',
'#size' => 15,
// This field should stay LTR even for RTL languages.
'#field_prefix' => '<span dir="ltr">' . self::GROUP_PREFIX,
'#field_suffix' => '</span>‎',
'#description' => $this
->t('A unique machine-readable name containing letters, numbers, and underscores.'),
'#maxlength' => FieldStorageConfig::NAME_MAX_LENGTH - strlen(self::GROUP_PREFIX),
'#machine_name' => array(
'source' => array(
'new_group_wrapper',
'label',
),
'exists' => array(
$this,
'groupNameExists',
),
),
'#required' => TRUE,
);
$form['actions'] = array(
'#type' => 'actions',
);
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => $this
->t('Save and continue'),
'#button_type' => 'primary',
'#validate' => array(
array(
$this,
'validateFormatterSelection',
),
),
);
$form['#attached']['library'][] = 'field_ui/drupal.field_ui';
}