Skip to content

Instantly share code, notes, and snippets.

@joshuataylor
Created July 29, 2015 11:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshuataylor/ca72d6231c669955b7b9 to your computer and use it in GitHub Desktop.
Save joshuataylor/ca72d6231c669955b7b9 to your computer and use it in GitHub Desktop.
From 42d8eefe4554b1c33df2443063193924e260faf4 Mon Sep 17 00:00:00 2001
From: Josh Taylor <joshuataylorx@gmail.com>
Date: Sun, 26 Jul 2015 23:20:36 +1000
Subject: [PATCH] Issue #2528914 by bojanz, joshtaylor: Rename store routes
---
modules/store/commerce_store.links.task.yml | 5 +++
modules/store/commerce_store.routing.yml | 13 +++++--
modules/store/src/Controller/StoreController.php | 44 ++++++++++++++++++++++++
modules/store/src/Entity/Store.php | 6 ++--
4 files changed, 63 insertions(+), 5 deletions(-)
create mode 100644 modules/store/src/Controller/StoreController.php
diff --git a/modules/store/commerce_store.links.task.yml b/modules/store/commerce_store.links.task.yml
index a14f3f7..4454b95 100644
--- a/modules/store/commerce_store.links.task.yml
+++ b/modules/store/commerce_store.links.task.yml
@@ -1,3 +1,8 @@
+entity.commerce_store.canonical:
+ route_name: entity.commerce_store.canonical
+ base_route: entity.commerce_store.canonical
+ title: View
+
entity.commerce_store.collection:
route_name: entity.commerce_store.collection
base_route: entity.commerce_store.collection
diff --git a/modules/store/commerce_store.routing.yml b/modules/store/commerce_store.routing.yml
index 65199c5..2ef50f1 100644
--- a/modules/store/commerce_store.routing.yml
+++ b/modules/store/commerce_store.routing.yml
@@ -29,7 +29,7 @@ entity.commerce_store.collection:
_permission: 'administer stores'
entity.commerce_store.edit_form:
- path: '/admin/commerce/stores/{commerce_store}/edit'
+ path: '/store/{commerce_store}/edit'
defaults:
_entity_form: commerce_store.edit
_title: 'Edit a store'
@@ -37,13 +37,22 @@ entity.commerce_store.edit_form:
_entity_access: 'commerce_store.edit'
entity.commerce_store.delete_form:
- path: '/admin/commerce/stores/{commerce_store}/delete'
+ path: '/store/{commerce_store}/delete'
defaults:
_entity_form: commerce_store.delete
_title: 'Delete a store'
requirements:
_entity_access: 'commerce_store.delete'
+entity.commerce_store.canonical:
+ path: '/store/{commerce_store}'
+ defaults:
+ _entity_view: 'commerce_store'
+ _title_callback: '\Drupal\commerce_store\Controller\StoreController::viewStoreTitle'
+ requirements:
+ _entity_access: 'commerce_store.view'
+
+
entity.commerce_store_type.add_form:
path: '/admin/commerce/config/store-types/add'
defaults:
diff --git a/modules/store/src/Controller/StoreController.php b/modules/store/src/Controller/StoreController.php
new file mode 100644
index 0000000..6f9b18f
--- /dev/null
+++ b/modules/store/src/Controller/StoreController.php
@@ -0,0 +1,44 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\commerce_store\Controller\StoreController.
+ */
+
+namespace Drupal\commerce_store\Controller;
+
+use Drupal\Core\Controller\ControllerBase;
+use Drupal\commerce_store\StoreInterface;
+
+/**
+ * Gets responses for Commerce Store routes.
+ */
+class StoreController extends ControllerBase {
+
+ /**
+ * The _title_callback for the entity.commerce_store.edit_form route
+ *
+ * @param \Drupal\commerce_store\StoreInterface $commerce_store
+ * The current store.
+ *
+ * @return string
+ * The page title
+ */
+ public function editPageTitle(StoreInterface $commerce_store) {
+ return $this->t('Editing @label', ['@label' => $commerce_store->label()]);
+ }
+
+ /**
+ * The _title_callback for the entity.commerce_store.canonical route
+ *
+ * @param \Drupal\commerce_store\StoreInterface $commerce_store
+ * The current store.
+ *
+ * @return string
+ * The page title
+ */
+ public function viewStoreTitle(StoreInterface $commerce_store) {
+ return \Drupal\Component\Utility\Xss::filter($commerce_store->label());
+ }
+
+}
diff --git a/modules/store/src/Entity/Store.php b/modules/store/src/Entity/Store.php
index f7172d7..01fc4e4 100644
--- a/modules/store/src/Entity/Store.php
+++ b/modules/store/src/Entity/Store.php
@@ -49,9 +49,9 @@
* "uuid" = "uuid"
* },
* links = {
- * "canonical" = "/admin/commerce/stores/{commerce_store}",
- * "edit-form" = "/admin/commerce/stores/{commerce_store}/edit",
- * "delete-form" = "/admin/commerce/stores/{commerce_store}/delete",
+ * "canonical" = "/store/{commerce_store}",
+ * "edit-form" = "/store/{commerce_store}/edit",
+ * "delete-form" = "/store/{commerce_store}/delete",
* "collection" = "/admin/commerce/stores",
* },
* bundle_entity_type = "commerce_store_type",
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment