YamlFormWizardPage.php in YAML Form 8
File
src/Plugin/YamlFormElement/YamlFormWizardPage.php
View source
<?php
namespace Drupal\yamlform\Plugin\YamlFormElement;
use Drupal\Core\Form\FormStateInterface;
use Drupal\yamlform\YamlFormInterface;
class YamlFormWizardPage extends Details {
public function getDefaultProperties() {
return [
'title' => '',
'open' => FALSE,
'prev_button_label' => '',
'next_button_label' => '',
];
}
public function getTranslatableProperties() {
return array_merge(parent::getTranslatableProperties(), [
'prev_button_label',
'next_button_label',
]);
}
public function isInput(array $element) {
return FALSE;
}
public function isContainer(array $element) {
return TRUE;
}
public function isRoot() {
return TRUE;
}
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
$yamlform = $form_state
->getFormObject()
->getYamlForm();
$form['wizard_page'] = [
'#type' => 'fieldset',
'#title' => $this
->t('Page settings'),
];
$form['wizard_page']['prev_button_label'] = [
'#type' => 'textfield',
'#title' => $this
->t('Previous page button label'),
'#description' => $this
->t('This is used for the Next Page button on the page before this page break.') . '<br/>' . $this
->t('Defaults to: %value', [
'%value' => $this
->getDefaultSettings($yamlform, 'wizard_prev_button_label'),
]),
];
$form['wizard_page']['next_button_label'] = [
'#type' => 'textfield',
'#title' => $this
->t('Next page button label'),
'#description' => $this
->t('This is used for the Previous Page button on the page after this page break.') . '<br/>' . $this
->t('Defaults to: %value', [
'%value' => $this
->getDefaultSettings($yamlform, 'wizard_next_button_label'),
]),
];
return $form;
}
protected function getDefaultSettings(YamlFormInterface $yamlform, $name) {
return $yamlform
->getSetting($name) ?: \Drupal::config('yamlform.settings')
->get("settings.default_{$name}");
}
}