class FormStep in Simple multi step form 8
Same name in this branch
- 8 src/FormStep.php \Drupal\simple_multistep\FormStep
- 8 src/Plugin/field_group/FieldGroupFormatter/FormStep.php \Drupal\simple_multistep\Plugin\field_group\FieldGroupFormatter\FormStep
Same name and namespace in other branches
- 8.x src/Plugin/field_group/FieldGroupFormatter/FormStep.php \Drupal\simple_multistep\Plugin\field_group\FieldGroupFormatter\FormStep
Plugin implementation of the 'form_step' formatter.
Plugin annotation
@FieldGroupFormatter(
id = "form_step",
label = @Translation("Form step"),
description = @Translation("Provide simple form step"),
supported_contexts = {
"form",
}
)
Hierarchy
- class \Drupal\simple_multistep\Plugin\field_group\FieldGroupFormatter\FormStep extends \Drupal\field_group\FieldGroupFormatterBase
Expanded class hierarchy of FormStep
File
- src/
Plugin/ field_group/ FieldGroupFormatter/ FormStep.php, line 20
Namespace
Drupal\simple_multistep\Plugin\field_group\FieldGroupFormatterView source
class FormStep extends FieldGroupFormatterBase {
/**
* {@inheritdoc}
*/
public function process(&$element, $processed_object) {
$element += [
'#type' => 'container',
'#attributes' => [],
];
if ($this
->getSetting('id')) {
$element['#id'] = Html::getUniqueId($this
->getSetting('id'));
}
$classes = $this
->getClasses();
if (!empty($classes)) {
$element['#attributes'] += [
'class' => $classes,
];
}
if ($this
->getSetting('required_fields')) {
$element['#attached']['library'][] = 'field_group/formatter.fieldset';
$element['#attached']['library'][] = 'field_group/core';
}
}
/**
* {@inheritdoc}
*/
public function preRender(&$element, $rendering_object) {
parent::preRender($element, $rendering_object);
$this
->process($element, $rendering_object);
}
/**
* {@inheritdoc}
*/
public function settingsForm() {
$form = parent::settingsForm();
$form['label']['#title'] = $this
->t('Step title');
$form['show_step_title'] = [
'#title' => $this
->t('Show step title'),
'#type' => 'checkbox',
'#default_value' => $this
->getSetting('show_step_title'),
'#description' => $this
->t('Show step title'),
'#weight' => 1,
];
$form['back_button_show'] = [
'#title' => $this
->t('Show back button'),
'#type' => 'checkbox',
'#default_value' => $this
->getSetting('back_button_show'),
'#description' => $this
->t('Back button for form. Don`t show on first step'),
'#weight' => 2,
];
$form['back_button_text'] = [
'#title' => $this
->t('Text for back button'),
'#type' => 'textfield',
'#default_value' => $this
->getSetting('back_button_text'),
'#description' => $this
->t('Text which will be show on back button'),
'#weight' => $form['back_button_show']['#weight'] + 0.1,
];
$form['next_button_text'] = [
'#title' => $this
->t('Text for next button'),
'#type' => 'textfield',
'#default_value' => $this
->getSetting('next_button_text'),
'#description' => $this
->t('Text which will be show on next button'),
];
return $form;
}
/**
* {@inheritdoc}
*/
public function settingsSummary() {
$summary = parent::settingsSummary();
$summary[] = $this
->t('Back button: @element', [
'@element' => $this
->getSetting('back_button_show') ? 'Show' : 'Hide',
]);
$summary[] = $this
->t('Show title: @element', [
'@element' => $this
->getSetting('show_step_title') ? 'Show' : 'Hide',
]);
return $summary;
}
/**
* {@inheritdoc}
*/
public static function defaultContextSettings($context) {
$defaults = [
'back_button_show' => FALSE,
'back_button_text' => t('Back'),
'next_button_text' => t('Next'),
'show_step_title' => TRUE,
] + parent::defaultSettings($context);
if ($context == 'form') {
$defaults['required_fields'] = 1;
}
return $defaults;
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FormStep:: |
public static | function | ||
FormStep:: |
public | function | ||
FormStep:: |
public | function | ||
FormStep:: |
public | function | ||
FormStep:: |
public | function |