public function YamlFormMessage::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 YamlFormMarkupBase::form
File
- src/
Plugin/ YamlFormElement/ YamlFormMessage.php, line 69
Class
- YamlFormMessage
- Provides a 'yamlform_message' element.
Namespace
Drupal\yamlform\Plugin\YamlFormElementCode
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
$form['markup']['#title'] = $this
->t('Message settings');
$form['markup']['message_type'] = [
'#type' => 'select',
'#title' => $this
->t('Message type'),
'#options' => [
'status' => t('Status'),
'error' => t('Error'),
'warning' => t('Warning'),
'info' => t('Info'),
],
];
$form['markup']['message_message'] = [
'#type' => 'yamlform_html_editor',
'#title' => $this
->t('Message content'),
];
$form['markup']['message_close'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Allow users to close the message.'),
'#return_value' => TRUE,
];
$form['markup']['message_close_effect'] = [
'#type' => 'select',
'#title' => $this
->t('Message close effect'),
'#options' => [
'hide' => $this
->t('Hide'),
'slide' => $this
->t('Slide'),
'fade' => $this
->t('Fade'),
],
'#states' => [
'visible' => [
':input[name="properties[message_close]"]' => [
'checked' => TRUE,
],
],
],
];
$form['markup']['message_storage'] = [
'#type' => 'radios',
'#title' => $this
->t('Message storage'),
'#options' => [
YamlFormMessageElement::STORAGE_NONE => $this
->t('None: Message state is never stored.'),
YamlFormMessageElement::STORAGE_SESSION => $this
->t('Session storage: Message state is reset after the browser is closed.'),
YamlFormMessageElement::STORAGE_LOCAL => $this
->t('Local storage: Message state persists after the browser is closed.'),
YamlFormMessageElement::STORAGE_USER => $this
->t("User data: Message state is saved to the current user's data. (Applies to authenticated users only)"),
YamlFormMessageElement::STORAGE_STATE => $this
->t("State API: Message state is saved to the site's system state. (Applies to authenticated users only)"),
],
'#states' => [
'visible' => [
':input[name="properties[message_close]"]' => [
'checked' => TRUE,
],
],
],
];
$form['markup']['message_id'] = [
'#type' => 'textfield',
'#title' => $this
->t('Message ID'),
'#description' => $this
->t("Unique ID used to store the message's closed state. Please enter only lower-case letters, numbers, dashes, and underscores.") . '<br/>' . $this
->t('Defaults to: %value', [
'%value' => '[yamlform:id]--[element:key]',
]),
'#pattern' => '/^[a-z0-9-_]+$/',
'#states' => [
'visible' => [
':input[name="properties[message_close]"]' => [
'checked' => TRUE,
],
],
],
];
return $form;
}