Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / chi-teck / drupal-code-generator / templates / d8 / module / content-entity / src / Form / ExampleForm.php.twig
diff --git a/vendor/chi-teck/drupal-code-generator/templates/d8/module/content-entity/src/Form/ExampleForm.php.twig b/vendor/chi-teck/drupal-code-generator/templates/d8/module/content-entity/src/Form/ExampleForm.php.twig
new file mode 100755 (executable)
index 0000000..7198536
--- /dev/null
@@ -0,0 +1,37 @@
+<?php
+
+namespace Drupal\{{ machine_name }}\Form;
+
+use Drupal\Core\Entity\ContentEntityForm;
+use Drupal\Core\Form\FormStateInterface;
+
+/**
+ * Form controller for the {{ entity_type_label|lower }} entity edit forms.
+ */
+class {{ class_prefix }}Form extends ContentEntityForm {
+
+  /**
+   * {@inheritdoc}
+   */
+  public function save(array $form, FormStateInterface $form_state) {
+
+    $entity = $this->getEntity();
+    $result = $entity->save();
+    $link = $entity->toLink($this->t('View'))->toRenderable();
+
+    $message_arguments = ['%label' => $this->entity->label()];
+    $logger_arguments = $message_arguments + ['link' => render($link)];
+
+    if ($result == SAVED_NEW) {
+      drupal_set_message($this->t('New {{ entity_type_label|lower }} %label has been created.', $message_arguments));
+      $this->logger('{{ machine_name }}')->notice('Created new {{ entity_type_label|lower }} %label', $logger_arguments);
+    }
+    else {
+      drupal_set_message($this->t('The {{ entity_type_label|lower }} %label has been updated.', $message_arguments));
+      $this->logger('{{ machine_name }}')->notice('Created new {{ entity_type_label|lower }} %label.', $logger_arguments);
+    }
+
+    $form_state->setRedirect('entity.{{ entity_type_id }}.canonical', ['{{ entity_type_id }}' => $entity->id()]);
+  }
+
+}