From 0524ce9bd4a41395726ec6e5cf8819eeecc12c29 Mon Sep 17 00:00:00 2001 From: Jesus Manuel Olivas Date: Mon, 13 Oct 2014 16:42:27 -0700 Subject: [PATCH 1/6] Update accesscontrolhandler Template --- .../src/accesscontrolhandler-entity-content.php.twig | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Resources/skeleton/module/src/accesscontrolhandler-entity-content.php.twig b/src/Resources/skeleton/module/src/accesscontrolhandler-entity-content.php.twig index 9049a4bc9..4e4dfcbf0 100644 --- a/src/Resources/skeleton/module/src/accesscontrolhandler-entity-content.php.twig +++ b/src/Resources/skeleton/module/src/accesscontrolhandler-entity-content.php.twig @@ -12,6 +12,7 @@ namespace Drupal\{{module}}; use Drupal\Core\Entity\EntityAccessControlHandler; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Session\AccountInterface; +use Drupal\Core\Access\AccessResult; {% endblock %} {% block class_declaration %} @@ -31,26 +32,26 @@ class {{ entity_class }}AccessControlHandler extends EntityAccessControlHandler switch ($operation) { case 'view': - return $account->hasPermission('view {{ entity_class }} entity'); + return AccessResult::allowedIfHasPermission($account, 'view {{ entity_class }} entity'); break; case 'edit': - return $account->hasPermission('edit {{ entity_class }} entity'); + return AccessResult::allowedIfHasPermission($account, 'edit {{ entity_class }} entity'); break; case 'delete': - return $account->hasPermission('delete {{ entity_class }} entity'); + return AccessResult::allowedIfHasPermission($account, 'delete {{ entity_class }} entity'); break; } - return TRUE; + return AccessResult::allowed(); } /** * {@inheritdoc} */ protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) { - return $account->hasPermission('add {{ entity_class }} entity'); + return AccessResult::allowedIfHasPermission($account, 'add Bar entity'); } {% endblock %} From ea8bea5e1f10050bc6a8a37f20a8bca9475bdf92 Mon Sep 17 00:00:00 2001 From: Jesus Manuel Olivas Date: Mon, 13 Oct 2014 16:58:02 -0700 Subject: [PATCH 2/6] Rename method submit to formSubmit --- .../module/src/Entity/Form/entity-content-delete.php.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Resources/skeleton/module/src/Entity/Form/entity-content-delete.php.twig b/src/Resources/skeleton/module/src/Entity/Form/entity-content-delete.php.twig index cf09cac6b..c8a1fbf7a 100644 --- a/src/Resources/skeleton/module/src/Entity/Form/entity-content-delete.php.twig +++ b/src/Resources/skeleton/module/src/Entity/Form/entity-content-delete.php.twig @@ -48,7 +48,7 @@ class {{ entity_class }}DeleteForm extends ContentEntityConfirmFormBase /** * {@inheritdoc} */ - public function submit(array $form, FormStateInterface $form_state) { + public function submitForm(array &$form, FormStateInterface $form_state) { $this->entity->delete(); watchdog('content', '@type: deleted %title.', array('@type' => $this->entity->bundle(), '%title' => $this->entity->label())); From 0eb548ed4d4af5b3041f5c4b4b0ae62e7d231956 Mon Sep 17 00:00:00 2001 From: Jesus Manuel Olivas Date: Mon, 13 Oct 2014 16:59:40 -0700 Subject: [PATCH 3/6] Replace method setRedirect with setRedirectUrl --- .../module/src/Entity/Form/entity-content-delete.php.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Resources/skeleton/module/src/Entity/Form/entity-content-delete.php.twig b/src/Resources/skeleton/module/src/Entity/Form/entity-content-delete.php.twig index c8a1fbf7a..6f42f630f 100644 --- a/src/Resources/skeleton/module/src/Entity/Form/entity-content-delete.php.twig +++ b/src/Resources/skeleton/module/src/Entity/Form/entity-content-delete.php.twig @@ -52,6 +52,6 @@ class {{ entity_class }}DeleteForm extends ContentEntityConfirmFormBase $this->entity->delete(); watchdog('content', '@type: deleted %title.', array('@type' => $this->entity->bundle(), '%title' => $this->entity->label())); - $form_state->setRedirect('{{ entity_name }}.list'); + $form_state->setRedirectUrl($this->getCancelUrl()); } {% endblock %} From b1c9b28371d1e6e139999647adbb87607ebf5ec6 Mon Sep 17 00:00:00 2001 From: Jesus Manuel Olivas Date: Mon, 13 Oct 2014 17:00:15 -0700 Subject: [PATCH 4/6] Replace watchdog function with Drupal::logger --- .../module/src/Entity/Form/entity-content-delete.php.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Resources/skeleton/module/src/Entity/Form/entity-content-delete.php.twig b/src/Resources/skeleton/module/src/Entity/Form/entity-content-delete.php.twig index 6f42f630f..a35fef916 100644 --- a/src/Resources/skeleton/module/src/Entity/Form/entity-content-delete.php.twig +++ b/src/Resources/skeleton/module/src/Entity/Form/entity-content-delete.php.twig @@ -51,7 +51,7 @@ class {{ entity_class }}DeleteForm extends ContentEntityConfirmFormBase public function submitForm(array &$form, FormStateInterface $form_state) { $this->entity->delete(); - watchdog('content', '@type: deleted %title.', array('@type' => $this->entity->bundle(), '%title' => $this->entity->label())); + \Drupal::logger('{{module}}')->notice('content @type: deleted %title.', array('@type' => $this->entity->bundle(), '%title' => $this->entity->label())); $form_state->setRedirectUrl($this->getCancelUrl()); } {% endblock %} From 2d3c9f35c6fc0681d12eb451b2c33ec372d6d1db Mon Sep 17 00:00:00 2001 From: Jesus Manuel Olivas Date: Mon, 13 Oct 2014 17:22:33 -0700 Subject: [PATCH 5/6] Fix buildRow method --- .../listController-entity-content.php.twig | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Resources/skeleton/module/src/Entity/Controller/listController-entity-content.php.twig b/src/Resources/skeleton/module/src/Entity/Controller/listController-entity-content.php.twig index 142b8d5a7..06cc40865 100644 --- a/src/Resources/skeleton/module/src/Entity/Controller/listController-entity-content.php.twig +++ b/src/Resources/skeleton/module/src/Entity/Controller/listController-entity-content.php.twig @@ -11,6 +11,7 @@ namespace Drupal\{{module}}\Entity\Controller; {% block use_class %} use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityListBuilder; +use Drupal\Core\Url; {% endblock %} {% block class_declaration %} @@ -38,10 +39,14 @@ class {{ entity_class }}ListController extends EntityListBuilder public function buildRow(EntityInterface $entity) { /* @var $entity \Drupal\{{module}}\Entity\{{ entity_class }} */ $row['id'] = $entity->id(); - $row['name'] = \Drupal::l($this->getLabel($entity), - '{{ entity_name }}.list', array( - '{{module}}_{{ entity_name }}' => $entity->id(), - )); + $row['name'] = \Drupal::l( + $this->getLabel($entity), + new Url( + '{{ entity_name }}.edit', array( + 'bar' => $entity->id(), + ) + ) + ); return $row + parent::buildRow($entity); } {% endblock %} From 09fcdf162a79a4ff34d7db3563db50063dbed432 Mon Sep 17 00:00:00 2001 From: Jesus Manuel Olivas Date: Mon, 13 Oct 2014 19:28:01 -0700 Subject: [PATCH 6/6] Remove setRedirect on submit function --- .../skeleton/module/src/Entity/Form/entity-content.php.twig | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Resources/skeleton/module/src/Entity/Form/entity-content.php.twig b/src/Resources/skeleton/module/src/Entity/Form/entity-content.php.twig index 9c27f8f02..1467c24e3 100644 --- a/src/Resources/skeleton/module/src/Entity/Form/entity-content.php.twig +++ b/src/Resources/skeleton/module/src/Entity/Form/entity-content.php.twig @@ -48,7 +48,6 @@ class {{ entity_class }}Form extends ContentEntityForm public function submit(array $form, FormStateInterface $form_state) { // Build the entity object from the submitted values. $entity = parent::submit($form, $form_state); - $form_state->setRedirect('{{ entity_name }}.list'); return $entity; }