public function WebformCompositeBase::form in Webform 6.x
Same name and namespace in other branches
- 8.5 src/Plugin/WebformElement/WebformCompositeBase.php \Drupal\webform\Plugin\WebformElement\WebformCompositeBase::form()
Gets the actual configuration webform array to be built.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array An associative array contain the element's configuration webform without any default values.
Overrides WebformElementBase::form
4 calls to WebformCompositeBase::form()
- Address::form in src/
Plugin/ WebformElement/ Address.php - Gets the actual configuration webform array to be built.
- WebformCustomComposite::form in src/
Plugin/ WebformElement/ WebformCustomComposite.php - Gets the actual configuration webform array to be built.
- WebformLocationBase::form in src/
Plugin/ WebformElement/ WebformLocationBase.php - Gets the actual configuration webform array to be built.
- WebformTelephone::form in src/
Plugin/ WebformElement/ WebformTelephone.php - Gets the actual configuration webform array to be built.
4 methods override WebformCompositeBase::form()
- Address::form in src/
Plugin/ WebformElement/ Address.php - Gets the actual configuration webform array to be built.
- WebformCustomComposite::form in src/
Plugin/ WebformElement/ WebformCustomComposite.php - Gets the actual configuration webform array to be built.
- WebformLocationBase::form in src/
Plugin/ WebformElement/ WebformLocationBase.php - Gets the actual configuration webform array to be built.
- WebformTelephone::form in src/
Plugin/ WebformElement/ WebformTelephone.php - Gets the actual configuration webform array to be built.
File
- src/
Plugin/ WebformElement/ WebformCompositeBase.php, line 857
Class
- WebformCompositeBase
- Provides a base for composite elements.
Namespace
Drupal\webform\Plugin\WebformElementCode
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
// Update #default_value description.
$form['default']['default_value']['#description'] = $this
->t("The default value of the composite webform element as YAML.");
// Update #required label.
$form['validation']['required_container']['required']['#title'] .= ' <em>' . $this
->t('(Display purposes only)') . '</em>';
$form['validation']['required_container']['required']['#description'] = $this
->t('If checked, adds required indicator to the title, if visible. To required individual elements, also tick "Required" under the @name settings above.', [
'@name' => $this
->getPluginLabel(),
]);
// Update '#multiple__header_label'.
$form['element']['multiple__header_container']['multiple__header_label']['#states']['visible'][':input[name="properties[multiple__header]"]'] = [
'checked' => FALSE,
];
$form['composite'] = [
'#type' => 'fieldset',
'#title' => $this
->t('@title settings', [
'@title' => $this
->getPluginLabel(),
]),
'#attributes' => [
'class' => [
'webform-admin-composite-elements',
],
],
];
$form['composite']['element'] = $this
->buildCompositeElementsTable($form, $form_state);
$form['composite']['flexbox'] = [
'#type' => 'select',
'#title' => $this
->t('Use Flexbox'),
'#description' => $this
->t("If 'Automatic' is selected Flexbox layout will only be used if a 'Flexbox layout' element is included in the webform."),
'#options' => [
'' => $this
->t('Automatic'),
0 => $this
->t('No'),
1 => $this
->t('Yes'),
],
];
// Hide single item display when multiple item display is set to 'table'.
$form['display']['item']['#states']['invisible'] = [
':input[name="properties[format_items]"]' => [
'value' => 'table',
],
];
$form['#attached']['library'][] = 'webform/webform.admin.composite';
// Select2, Chosen, and/or Choices enhancements.
// @see \Drupal\webform\Plugin\WebformElement\Select::form
$select2_exists = $this->librariesManager
->isIncluded('jquery.select2');
$choices_exists = $this->librariesManager
->isIncluded('choices');
$chosen_exists = $this->librariesManager
->isIncluded('jquery.chosen');
$form['composite']['select2'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Select2'),
'#description' => $this
->t('Replace select element with jQuery <a href=":href">Select2</a> select box.', [
':href' => 'https://select2.github.io/',
]),
'#return_value' => TRUE,
'#states' => [
'disabled' => [
':input[name="properties[chosen]"]' => [
'checked' => TRUE,
],
],
],
];
if (!$select2_exists) {
$form['composite']['select2']['#access'] = FALSE;
}
$form['composite']['choices'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Choices'),
'#description' => $this
->t('Replace select element with <a href=":href">Choice.js</a> select box.', [
':href' => 'https://joshuajohnson.co.uk/Choices/',
]),
'#return_value' => TRUE,
'#states' => [
'disabled' => [
':input[name="properties[select2]"]' => [
'checked' => TRUE,
],
],
],
];
if (!$choices_exists) {
$form['composite']['choices']['#access'] = FALSE;
}
$form['composite']['chosen'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Chosen'),
'#description' => $this
->t('Replace select element with jQuery <a href=":href">Chosen</a> select box.', [
':href' => 'https://harvesthq.github.io/chosen/',
]),
'#return_value' => TRUE,
'#states' => [
'disabled' => [
':input[name="properties[select2]"]' => [
'checked' => TRUE,
],
],
],
];
if (!$chosen_exists) {
$form['composite']['chosen']['#access'] = FALSE;
}
if ($select2_exists + $chosen_exists + $choices_exists > 1) {
$select_libraries = [];
if ($select2_exists) {
$select_libraries[] = $this
->t('Select2');
}
if ($choices_exists) {
$select_libraries[] = $this
->t('Choices');
}
if ($chosen_exists) {
$select_libraries[] = $this
->t('Chosen');
}
$t_args = [
'@libraries' => WebformArrayHelper::toString($select_libraries),
];
$form['composite']['select_message'] = [
'#type' => 'webform_message',
'#message_type' => 'warning',
'#message_message' => $this
->t('@libraries provide very similar functionality, only one should be enabled.', $t_args),
'#access' => TRUE,
];
}
return $form;
}