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\EntityForm;
13 use Drupal\Core\Form\FormStateInterface;
16 {% block class_declaration %}
18 * Class {{ entity_class }}Form.
20 class {{ entity_class }}Form extends EntityForm {% endblock %}
21 {% block class_methods %}
25 public function form(array $form, FormStateInterface $form_state) {
26 $form = parent::form($form, $form_state);
28 ${{ entity_name | machine_name }} = $this->entity;
30 '#type' => 'textfield',
31 '#title' => $this->t('Label'),
33 '#default_value' => ${{ entity_name | machine_name }}->label(),
34 '#description' => $this->t("Label for the {{ label }}."),
39 '#type' => 'machine_name',
40 '#default_value' => ${{ entity_name | machine_name }}->id(),
42 'exists' => '\Drupal\{{ module }}\Entity\{{ entity_class }}::load',
44 '#disabled' => !${{ entity_name | machine_name }}->isNew(),
47 /* You will need additional form elements for your custom properties. */
55 public function save(array $form, FormStateInterface $form_state) {
56 ${{ entity_name | machine_name }} = $this->entity;
57 $status = ${{ entity_name | machine_name }}->save();
61 drupal_set_message($this->t('Created the %label {{ label }}.', [
62 '%label' => ${{ entity_name | machine_name }}->label(),
67 drupal_set_message($this->t('Saved the %label {{ label }}.', [
68 '%label' => ${{ entity_name | machine_name }}->label(),
71 $form_state->setRedirectUrl(${{ entity_name | machine_name }}->toUrl('collection'));