public function ModalForm::buildForm in Modal 8.3
Same name and namespace in other branches
- 8.2 src/Form/ModalForm.php \Drupal\modal_page\Form\ModalForm::buildForm()
Form constructor.
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 The form structure.
Overrides EntityForm::buildForm
File
- src/
Form/ ModalForm.php, line 32
Class
- ModalForm
- Class: ModalForm.
Namespace
Drupal\modal_page\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$form = parent::buildForm($form, $form_state);
$entity = $this->entity;
$default_language = $entity
->getUntranslated()
->language()
->getId();
if (!empty($entity->langcode->value)) {
$default_language = $entity->langcode->value;
}
$languages = $this->languageManager
->getCurrentLanguage();
$form['pages']['#states']['visible'][] = [
':input[id="edit-type"]' => [
'value' => 'page',
],
];
$form['parameters']['#states']['visible'][] = [
':input[id="edit-type"]' => [
'value' => 'parameter',
],
];
$form['langcode'] = [
'#title' => $this
->t('Language'),
'#type' => 'language_select',
'#default_value' => $default_language,
'#empty_option' => $this
->t('- Any -'),
];
if ($this
->isMonoLanguage($languages)) {
$disabled = [
'disabled' => 'disabled',
];
$form['langcode']['#attributes'] = $disabled;
}
$form['advanced'] = [
'#type' => 'details',
'#title' => $this
->t('Advanced'),
];
$form['advanced']['modal_customization'] = [
'#type' => 'details',
'#title' => $this
->t('Customization'),
];
$form['advanced']['modal_customization']['ok_button'] = [
'#type' => 'details',
'#title' => $this
->t('OK Button'),
];
$form['advanced']['modal_customization']['ok_button']['ok_label_button'] = $form['ok_label_button'];
$form['advanced']['modal_customization']['dont_show_again'] = [
'#type' => 'details',
'#title' => $this
->t("Don't show again"),
];
$form['advanced']['modal_customization']['dont_show_again']['enable_dont_show_again_option'] = $form['enable_dont_show_again_option'];
$form['advanced']['modal_customization']['dont_show_again']['dont_show_again_label'] = $form['dont_show_again_label'];
$form['advanced']['modal_customization']['dont_show_again']['dont_show_again_label']['#states']['visible'][] = [
':input[name="enable_dont_show_again_option[value]"]' => [
'checked' => TRUE,
],
];
$form['advanced']['modal_customization']['modal_size'] = [
'#type' => 'details',
'#title' => $this
->t("Modal Size"),
];
$form['advanced']['modal_customization']['modal_size']['modal_size'] = $form['modal_size'];
$form['advanced']['modal_customization']['close_modal_options'] = [
'#type' => 'details',
'#title' => $this
->t("Close Modal"),
];
$form['advanced']['modal_customization']['close_modal_options']['close_modal_esc_key'] = $form['close_modal_esc_key'];
$form['advanced']['modal_customization']['close_modal_options']['close_modal_clicking_outside'] = $form['close_modal_clicking_outside'];
$form['advanced']['roles_restriction'] = [
'#type' => 'details',
'#title' => $this
->t('Roles Restriction'),
];
$form['advanced']['roles_restriction']['roles'] = $form['roles'];
$form['advanced']['extras'] = [
'#type' => 'details',
'#title' => $this
->t('Extras'),
];
$form['advanced']['extras']['type'] = $form['type'];
$form['advanced']['extras']['delay_display'] = $form['delay_display'];
$form['advanced']['extras']['published'] = $form['published'];
unset($form['type']);
unset($form['published']);
unset($form['delay_display']);
unset($form['modal_size']);
unset($form['ok_label_button']);
unset($form['enable_dont_show_again_option']);
unset($form['dont_show_again_label']);
unset($form['close_modal_esc_key']);
unset($form['close_modal_clicking_outside']);
unset($form['roles']);
$form['actions']['cancel'] = [
'#type' => 'link',
'#title' => $this
->t('Cancel'),
'#value' => $this
->t('Cancel'),
'#button_type' => 'primary',
'#url' => Url::fromRoute('modal_page.default'),
'#attributes' => [
'class' => 'button js-form-submit form-submit',
],
'#weight' => 20,
];
$form['actions']['delete']['#weight'] = 21;
return $form;
}