Yaffs site version 1.1
[yaffs-website] / vendor / drupal / console / templates / module / src / Entity / Form / entity-content.php.twig
1 {% extends "base/class.php.twig" %}
2
3 {% block file_path %}
4 \Drupal\{{module}}\Form\{{ entity_class }}Form.
5 {% endblock %}
6
7 {% block namespace_class %}
8 namespace Drupal\{{module}}\Form;
9 {% endblock %}
10
11 {% block use_class %}
12 use Drupal\Core\Entity\ContentEntityForm;
13 use Drupal\Core\Form\FormStateInterface;
14 {% endblock %}
15
16 {% block class_declaration %}
17 /**
18  * Form controller for {{ label }} edit forms.
19  *
20  * @ingroup {{module}}
21  */
22 class {{ entity_class }}Form extends ContentEntityForm {% endblock %}
23 {% block class_methods %}
24   /**
25    * {@inheritdoc}
26    */
27   public function buildForm(array $form, FormStateInterface $form_state) {
28     /* @var $entity \Drupal\{{module}}\Entity\{{ entity_class }} */
29     $form = parent::buildForm($form, $form_state);
30 {% if revisionable %}
31
32     if (!$this->entity->isNew()) {
33       $form['new_revision'] = [
34         '#type' => 'checkbox',
35         '#title' => $this->t('Create new revision'),
36         '#default_value' => FALSE,
37         '#weight' => 10,
38       ];
39     }
40 {% endif %}
41
42     $entity = $this->entity;
43
44     return $form;
45   }
46
47   /**
48    * {@inheritdoc}
49    */
50   public function save(array $form, FormStateInterface $form_state) {
51     $entity = &$this->entity;
52 {% if revisionable %}
53
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();
57
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());
61     }
62     else {
63       $entity->setNewRevision(FALSE);
64     }
65 {% endif %}
66
67     $status = parent::save($form, $form_state);
68
69     switch ($status) {
70       case SAVED_NEW:
71         drupal_set_message($this->t('Created the %label {{ label }}.', [
72           '%label' => $entity->label(),
73         ]));
74         break;
75
76       default:
77         drupal_set_message($this->t('Saved the %label {{ label }}.', [
78           '%label' => $entity->label(),
79         ]));
80     }
81     $form_state->setRedirect('entity.{{ entity_name }}.canonical', ['{{ entity_name }}' => $entity->id()]);
82   }
83 {% endblock %}