View source
<?php
namespace Drupal\forms_steps\Form;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
class FormsStepsStepEditForm extends FormsStepsStepFormBase {
public function getFormId() {
return 'forms_steps_step_edit_form';
}
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
$form['id']['#default_value'] = $this->stepId;
$form['id']['#disabled'] = TRUE;
return $form;
}
public function save(array $form, FormStateInterface $form_state) {
$forms_steps = $this->entity;
$forms_steps
->save();
$this
->messenger()
->addMessage($this
->t('Saved %label step.', [
'%label' => $forms_steps
->getStep($this->stepId)
->label(),
]));
$form_state
->setRedirectUrl($forms_steps
->toUrl('edit-form'));
Cache::invalidateTags([
'entity_types',
'routes',
'local_tasks',
'local_task',
'local_action',
'rendered',
]);
}
protected function actions(array $form, FormStateInterface $form_state) {
$actions['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Save'),
'#submit' => [
'::submitForm',
'::save',
],
];
$actions['delete'] = [
'#type' => 'link',
'#title' => $this
->t('Delete'),
'#access' => $this->entity
->access('delete-state:' . $this->stepId),
'#attributes' => [
'class' => [
'button',
'button--danger',
],
],
'#url' => Url::fromRoute('entity.forms_steps.delete_step_form', [
'forms_steps' => $this->entity
->id(),
'forms_steps_step' => $this->stepId,
]),
];
return $actions;
}
}