View source
<?php
namespace Drupal\webform\Plugin\WebformElement;
use Drupal\Core\Form\FormStateInterface;
use Drupal\webform\Plugin\WebformElementWizardPageInterface;
use Drupal\webform\Utility\WebformElementHelper;
use Drupal\webform\WebformInterface;
use Drupal\webform\WebformSubmissionInterface;
class WebformWizardPage extends Details implements WebformElementWizardPageInterface {
protected function defineDefaultProperties() {
$properties = [
'title' => '',
'open' => FALSE,
'prev_button_label' => '',
'next_button_label' => '',
'attributes' => [],
'format' => $this
->getItemDefaultFormat(),
'format_html' => '',
'format_text' => '',
'format_attributes' => [],
] + $this
->defineDefaultBaseProperties();
unset($properties['flex']);
return $properties;
}
protected function defineTranslatableProperties() {
return array_merge(parent::defineTranslatableProperties(), [
'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 preview() {
return [];
}
protected function formatHtmlItem(array $element, WebformSubmissionInterface $webform_submission, array $options = []) {
$build = parent::formatHtmlItem($element, $webform_submission, $options);
if ($build && isset($options['view_mode']) && $options['view_mode'] === 'preview' && $webform_submission
->getWebform()
->getSetting('wizard_preview_link')) {
$build['#children']['wizard_page_link'] = [
'#type' => 'container',
'#attributes' => [
'data-webform-page' => $element['#webform_key'],
'class' => [
'webform-wizard-page-edit',
],
],
];
}
return $build;
}
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
$webform = $form_state
->getFormObject()
->getWebform();
$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 /><br />' . $this
->t('Defaults to: %value', [
'%value' => $webform
->getSetting('wizard_prev_button_label', TRUE),
]),
];
$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 /><br />' . $this
->t('Defaults to: %value', [
'%value' => $webform
->getSetting('wizard_next_button_label', TRUE),
]),
];
$form['conditional_logic']['states']['#multiple'] = FALSE;
return $form;
}
public function getElementSelectorOptions(array $element) {
return [];
}
public function getElementStateOptions() {
return [
'visible' => $this
->t('Visible'),
'invisible' => $this
->t('Hidden'),
];
}
public function showPage(array &$element) {
$element['#type'] = 'container';
}
public function hidePage(array &$element) {
WebformElementHelper::setPropertyRecursive($element, '#access', FALSE);
}
}