1 {% extends "base/class.php.twig" %}
4 \Drupal\{{module}}\Form\{{ entity_class }}Form.
7 {% block namespace_class %}
8 namespace Drupal\{{module}}\Form;
12 use Drupal\Core\Entity\ContentEntityForm;
13 use Drupal\Core\Form\FormStateInterface;
16 {% block class_declaration %}
18 * Form controller for {{ label }} edit forms.
22 class {{ entity_class }}Form extends ContentEntityForm {% endblock %}
23 {% block class_methods %}
27 public function buildForm(array $form, FormStateInterface $form_state) {
28 /* @var $entity \Drupal\{{module}}\Entity\{{ entity_class }} */
29 $form = parent::buildForm($form, $form_state);
32 if (!$this->entity->isNew()) {
33 $form['new_revision'] = [
34 '#type' => 'checkbox',
35 '#title' => $this->t('Create new revision'),
36 '#default_value' => FALSE,
42 $entity = $this->entity;
50 public function save(array $form, FormStateInterface $form_state) {
51 $entity = &$this->entity;
54 // Save as a new revision if requested to do so.
55 if (!$form_state->isValueEmpty('new_revision') && $form_state->getValue('new_revision') != FALSE) {
56 $entity->setNewRevision();
58 // If a new revision is created, save the current user as revision author.
59 $entity->setRevisionCreationTime(REQUEST_TIME);
60 $entity->setRevisionUserId(\Drupal::currentUser()->id());
63 $entity->setNewRevision(FALSE);
67 $status = parent::save($form, $form_state);
71 drupal_set_message($this->t('Created the %label {{ label }}.', [
72 '%label' => $entity->label(),
77 drupal_set_message($this->t('Saved the %label {{ label }}.', [
78 '%label' => $entity->label(),
81 $form_state->setRedirect('entity.{{ entity_name }}.canonical', ['{{ entity_name }}' => $entity->id()]);