X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fchi-teck%2Fdrupal-code-generator%2Ftemplates%2Fd8%2Fmodule%2Fconfiguration-entity%2Fsrc%2FForm%2FExampleForm.php.twig;fp=vendor%2Fchi-teck%2Fdrupal-code-generator%2Ftemplates%2Fd8%2Fmodule%2Fconfiguration-entity%2Fsrc%2FForm%2FExampleForm.php.twig;h=048b34d0dc6088d6bda88fce74d708e8cd241191;hp=0000000000000000000000000000000000000000;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0 diff --git a/vendor/chi-teck/drupal-code-generator/templates/d8/module/configuration-entity/src/Form/ExampleForm.php.twig b/vendor/chi-teck/drupal-code-generator/templates/d8/module/configuration-entity/src/Form/ExampleForm.php.twig new file mode 100644 index 000000000..048b34d0d --- /dev/null +++ b/vendor/chi-teck/drupal-code-generator/templates/d8/module/configuration-entity/src/Form/ExampleForm.php.twig @@ -0,0 +1,70 @@ + 'textfield', + '#title' => $this->t('Label'), + '#maxlength' => 255, + '#default_value' => $this->entity->label(), + '#description' => $this->t('Label for the {{ entity_type_label|lower }}.'), + '#required' => TRUE, + ]; + + $form['id'] = [ + '#type' => 'machine_name', + '#default_value' => $this->entity->id(), + '#machine_name' => [ + 'exists' => '\Drupal\{{ machine_name }}\Entity\{{ class_prefix }}::load', + ], + '#disabled' => !$this->entity->isNew(), + ]; + + $form['status'] = [ + '#type' => 'checkbox', + '#title' => $this->t('Enabled'), + '#default_value' => $this->entity->status(), + ]; + + $form['description'] = [ + '#type' => 'textarea', + '#title' => $this->t('Description'), + '#default_value' => $this->entity->get('description'), + '#description' => $this->t('Description of the {{ entity_type_label|lower }}.'), + ]; + + return $form; + } + + /** + * {@inheritdoc} + */ + public function save(array $form, FormStateInterface $form_state) { + $result = parent::save($form, $form_state); + $message_args = ['%label' => $this->entity->label()]; + $message = $result == SAVED_NEW + ? $this->t('Created new {{ entity_type_label|lower }} %label.', $message_args) + : $this->t('Updated {{ entity_type_label|lower }} %label.', $message_args); + drupal_set_message($message); + $form_state->setRedirectUrl($this->entity->toUrl('collection')); + return $result; + } + +}