public function Checkboxes::form in Webform 8.5
Same name and namespace in other branches
- 6.x src/Plugin/WebformElement/Checkboxes.php \Drupal\webform\Plugin\WebformElement\Checkboxes::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 OptionsBase::form
File
- src/
Plugin/ WebformElement/ Checkboxes.php, line 173
Class
- Checkboxes
- Provides a 'checkboxes' element.
Namespace
Drupal\webform\Plugin\WebformElementCode
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
// Checkboxes must require > 2 options.
$form['element']['multiple']['#min'] = 2;
// Include options all and none.
$option_types = [
'options_all' => $this
->t('All'),
'options_none' => $this
->t('None'),
];
foreach ($option_types as $option_type => $option_label) {
if (!$this
->hasProperty($option_type)) {
continue;
}
$t_args = [
'@type' => $option_label,
];
$form['options'][$option_type] = [
'#type' => 'checkbox',
'#title' => $this
->t("Include '@type of the above' option", $t_args),
'#return_value' => TRUE,
];
$form['options'][$option_type . '_container'] = $this
->getFormInlineContainer() + [
'#states' => [
'visible' => [
[
':input[name="properties[' . $option_type . ']"]' => [
'checked' => TRUE,
],
],
],
'required' => [
[
':input[name="properties[' . $option_type . ']"]' => [
'checked' => TRUE,
],
],
],
],
];
$form['options'][$option_type . '_container']['#attributes']['data-webform-states-no-clear'] = TRUE;
$form['options'][$option_type . '_container'][$option_type . '_value'] = [
'#type' => 'textfield',
'#title' => $this
->t("@type option value", $t_args),
];
$form['options'][$option_type . '_container'][$option_type . '_text'] = [
'#type' => 'textfield',
'#title' => $this
->t("@type option text", $t_args),
'#attributes' => [
'class' => [
'webform-ui-element-form-inline--input-double-width',
],
],
];
}
return $form;
}