Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forms entity content at core 8.0.x #174

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace Drupal\{{module}}\Entity\Form;

{% block use_class %}
use Drupal\Core\Entity\ContentEntityConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
{% endblock %}

Expand All @@ -33,7 +34,7 @@ class {{ entity_class }}DeleteForm extends ContentEntityConfirmFormBase
/**
* {@inheritdoc}
*/
public function getCancelRoute() {
public function getCancelUrl() {
return new Url('{{ entity_name }}.list');
}

Expand All @@ -47,10 +48,10 @@ class {{ entity_class }}DeleteForm extends ContentEntityConfirmFormBase
/**
* {@inheritdoc}
*/
public function submit(array $form, array &$form_state) {
public function submit(array $form, FormStateInterface $form_state) {
$this->entity->delete();

watchdog('content', '@type: deleted %title.', array('@type' => $this->entity->bundle(), '%title' => $this->entity->label()));
$form_state['redirect_route']['route_name'] = '{{ entity_name }}.list';
$form_state['redirect_route'] = $this->getCancelUrl();
}
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace Drupal\{{module}}\Entity\Form;

{% block use_class %}
use Drupal\Core\Entity\ContentEntityForm;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Language\Language;
{% endblock %}

Expand All @@ -26,7 +27,7 @@ class {{ entity_class }}Form extends ContentEntityForm
/**
* Overrides Drupal\Core\Entity\EntityFormController::buildForm().
*/
public function buildForm(array $form, array &$form_state) {
public function buildForm(array $form, FormStateInterface $form_state) {
/* @var $entity \Drupal\{{module}}\Entity\{{ entity_class }} */
$form = parent::buildForm($form, $form_state);
$entity = $this->entity;
Expand All @@ -44,7 +45,7 @@ class {{ entity_class }}Form extends ContentEntityForm
/**
* Overrides \Drupal\Core\Entity\EntityFormController::submit().
*/
public function submit(array $form, array &$form_state) {
public function submit(array $form, FormStateInterface $form_state) {
// Build the entity object from the submitted values.
$entity = parent::submit($form, $form_state);
$form_state['redirect_route']['route_name'] = '{{ entity_name }}.list';
Expand All @@ -55,7 +56,7 @@ class {{ entity_class }}Form extends ContentEntityForm
/**
* Overrides Drupal\Core\Entity\EntityFormController::save().
*/
public function save(array $form, array &$form_state) {
public function save(array $form, FormStateInterface $form_state) {
$entity = $this->entity;
$entity->save();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace Drupal\{{module}}\Entity\Form;

{% block use_class %}
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
{% endblock %}

{% block class_declaration %}
Expand Down Expand Up @@ -40,7 +41,7 @@ class {{ entity_class }}SettingsForm extends FormBase
* @param array $form_state
* An associative array containing the current state of the form.
*/
public function submitForm(array &$form, array &$form_state) {
public function submitForm(array &$form, FormStateInterface $form_state) {
// Empty implementation of the abstract submit class.
}

Expand All @@ -55,7 +56,7 @@ class {{ entity_class }}SettingsForm extends FormBase
* @param array $form_state
* An associative array containing the current state of the form.
*/
public function buildForm(array $form, array &$form_state) {
public function buildForm(array $form, FormStateInterface $form_state) {
$form['{{ entity_class }}_settings']['#markup'] = 'Settings form for {{ entity_class }}. Manage field settings here.';
return $form;
}
Expand Down