From 2cf897c92b9bc5ec71a56a9a9b514a7562177926 Mon Sep 17 00:00:00 2001 From: naomi Date: Thu, 12 Apr 2018 12:06:51 +0200 Subject: [PATCH] Changed path for adding hat to /zencrm/hat/{person_id}/.... Because the person id needs to be in third place in the URL, so that it filters the entity reference view for the contact details. But the second place cannot be "person" as then it would try to render the person blocks on th page. --- src/Controller/HatController.php | 4 ++-- src/Plugin/Block/HatCreator.php | 6 +++--- zencrm.routing.yml | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Controller/HatController.php b/src/Controller/HatController.php index 26d4b1b..9440acf 100644 --- a/src/Controller/HatController.php +++ b/src/Controller/HatController.php @@ -15,9 +15,9 @@ class HatController extends ControllerBase { * @return string * Return Hello string. */ - public function createHatForPerson($type, $person_id) { + public function createHatForPerson($person_id, $hat_type_id) { $values = array( - 'type' => $type, + 'type' => $hat_type_id, 'person' => $person_id ); diff --git a/src/Plugin/Block/HatCreator.php b/src/Plugin/Block/HatCreator.php index 8e2b22a..6b06160 100644 --- a/src/Plugin/Block/HatCreator.php +++ b/src/Plugin/Block/HatCreator.php @@ -25,13 +25,13 @@ class HatCreator extends BlockBase { // Only offer hat creation on hats they don't already have. $hat_types = \Drupal::service('entity_type.bundle.info')->getBundleInfo('hat'); - foreach($hat_types as $id => $type) { + foreach($hat_types as $hat_type_id => $type) { $hats = \Drupal::entityTypeManager() ->getStorage('hat') - ->loadByProperties(['type' => $id, 'person' => $person_id]); + ->loadByProperties(['type' => $hat_type_id, 'person' => $person_id]); if (!reset($hats)) { $label = $type['label']; - $markup .= "

Add a $label Hat

"; + $markup .= "

Add a $label Hat

"; } } return [ diff --git a/zencrm.routing.yml b/zencrm.routing.yml index 7abe79d..8721158 100644 --- a/zencrm.routing.yml +++ b/zencrm.routing.yml @@ -1,5 +1,5 @@ zencrm.hat.create: - path: '/zencrm/hat/add/{type}/{person_id}' + path: '/zencrm/hat/{person_id}/add/{hat_type_id}' defaults: _controller: '\Drupal\zencrm\Controller\HatController::createHatForPerson' _title: 'Add New Hat'