public function YamlFormOptionsForm::form in YAML Form 8
Gets the actual form array to be built.
Overrides EntityForm::form
See also
\Drupal\Core\Entity\EntityForm::processForm()
\Drupal\Core\Entity\EntityForm::afterBuild()
File
- src/
YamlFormOptionsForm.php, line 21
Class
- YamlFormOptionsForm
- Provides a form to set options.
Namespace
Drupal\yamlformCode
public function form(array $form, FormStateInterface $form_state) {
/** @var \Drupal\yamlform\YamlFormOptionsInterface $yamlform_options */
$yamlform_options = $this->entity;
$form['label'] = [
'#type' => 'textfield',
'#title' => $this
->t('Label'),
'#maxlength' => 255,
'#required' => TRUE,
'#attributes' => $yamlform_options
->isNew() ? [
'autofocus' => 'autofocus',
] : [],
'#default_value' => $yamlform_options
->label(),
];
$form['id'] = [
'#type' => 'machine_name',
'#machine_name' => [
'exists' => '\\Drupal\\yamlform\\Entity\\YamlFormOptions::load',
],
'#required' => TRUE,
'#disabled' => !$yamlform_options
->isNew(),
'#default_value' => $yamlform_options
->id(),
];
// Call the isolated edit form that can be overridden by the
// yamlform_ui.module.
$module_names = $this
->alterModuleNames();
if (count($module_names) && !$form_state
->getUserInput()) {
$t_args = [
'%title' => $yamlform_options
->label(),
'%module_names' => YamlFormArrayHelper::toString($module_names),
'@module' => new PluralTranslatableMarkup(count($module_names), $this
->t('module'), $this
->t('modules')),
];
if (empty($yamlform_options
->get('options'))) {
drupal_set_message($this
->t('The %title options are being set by the %module_names @module. Altering any of the below options will override these dynamically populated options.', $t_args), 'warning');
}
else {
drupal_set_message($this
->t('The %title options have been customized. Resetting the below options will allow the %module_names @module to dynamically populate these options.', $t_args), 'warning');
}
}
$form = $this
->editForm($form, $form_state);
return parent::form($form, $form_state);
}