public function YamlFormLikert::form in YAML Form 8
Gets the actual configuration form 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 form without any default values..
Overrides YamlFormElementBase::form
File
- src/
Plugin/ YamlFormElement/ YamlFormLikert.php, line 333
Class
- YamlFormLikert
- Provides a 'likert' element.
Namespace
Drupal\yamlform\Plugin\YamlFormElementCode
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
$form['likert'] = [
'#type' => 'fieldset',
'#title' => $this
->t('Likert settings'),
];
$form['likert']['questions'] = [
'#type' => 'yamlform_options',
'#title' => $this
->t('Questions'),
'#label' => $this
->t('question'),
'#labels' => $this
->t('questions'),
'#required' => TRUE,
];
$form['likert']['questions_randomize'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Randomize questions'),
'#description' => $this
->t('Randomizes the order of the questions when they are displayed in the form.'),
'#return_value' => TRUE,
];
$form['likert']['answers'] = [
'#type' => 'yamlform_element_options',
'#title' => $this
->t('Answers'),
'#likert' => TRUE,
'#required' => TRUE,
];
$form['likert']['na_answer'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Allow N/A answer'),
'#description' => $this
->t('Allowing N/A is ideal for situations where you wish to make a likert element required, but still want to allow users to opt out of certain questions.'),
'#return_value' => TRUE,
];
$form['likert']['na_answer_value'] = [
'#type' => 'textfield',
'#title' => $this
->t('N/A answer value'),
'#description' => $this
->t('Value stored in the database. Leave blank to store an empty string in the database.'),
'#states' => [
'visible' => [
':input[name="properties[na_answer]"]' => [
'checked' => TRUE,
],
],
],
];
$form['likert']['na_answer_text'] = [
'#type' => 'textfield',
'#title' => $this
->t('N/A answer text'),
'#description' => $this
->t('Text display display on form.'),
'#states' => [
'visible' => [
':input[name="properties[na_answer]"]' => [
'checked' => TRUE,
],
],
'required' => [
':input[name="properties[na_answer]"]' => [
'checked' => TRUE,
],
],
],
];
return $form;
}