From 4c8af3ef6646391145f2d130c13420252cbf3583 Mon Sep 17 00:00:00 2001 From: Jocelyn Fiat Date: Tue, 7 Jul 2015 17:20:25 +0200 Subject: [PATCH] Fixed implementation of path alias settings. Now report an error if path is already aliased to another location. --- .../demo/site/themes/bootstrap/assets/css/style.css | 6 ++++++ .../site/themes/bootstrap/assets/scss/style.scss | 5 +++++ modules/node/cms_node_api.e | 2 +- modules/node/handler/cms_node_type_webform_manager.e | 5 ++++- src/service/cms_api.e | 12 ++++++++++++ 5 files changed, 28 insertions(+), 2 deletions(-) diff --git a/examples/demo/site/themes/bootstrap/assets/css/style.css b/examples/demo/site/themes/bootstrap/assets/css/style.css index 45ffaa5..c2c79a9 100644 --- a/examples/demo/site/themes/bootstrap/assets/css/style.css +++ b/examples/demo/site/themes/bootstrap/assets/css/style.css @@ -76,3 +76,9 @@ ul.horizontal li { border-width: 2px 1px 0; padding: 2px 7px 1px; } + +#message li.error { + background-color: #f99; + border: solid 1px red; + padding: 5px 2px 5px 2px; +} diff --git a/examples/demo/site/themes/bootstrap/assets/scss/style.scss b/examples/demo/site/themes/bootstrap/assets/scss/style.scss index a6b5475..be72875 100644 --- a/examples/demo/site/themes/bootstrap/assets/scss/style.scss +++ b/examples/demo/site/themes/bootstrap/assets/scss/style.scss @@ -81,3 +81,8 @@ ul.horizontal { } } } +#message li.error { + background-color: #f99; + border: solid 1px red; + padding: 5px 2px 5px 2px; +} diff --git a/modules/node/cms_node_api.e b/modules/node/cms_node_api.e index 7abf7ef..0ff76d2 100644 --- a/modules/node/cms_node_api.e +++ b/modules/node/cms_node_api.e @@ -182,7 +182,7 @@ feature -- URL require a_node.has_id do - create Result.make (a_node.title, cms_api.path_alias (node_path (a_node))) + create Result.make (a_node.title, cms_api.location_alias (node_path (a_node))) end node_path (a_node: CMS_NODE): STRING diff --git a/modules/node/handler/cms_node_type_webform_manager.e b/modules/node/handler/cms_node_type_webform_manager.e index 5f1e4b5..221cfee 100644 --- a/modules/node/handler/cms_node_type_webform_manager.e +++ b/modules/node/handler/cms_node_type_webform_manager.e @@ -102,7 +102,7 @@ feature -- Forms ... if attached a_node.link as lnk then l_uri := lnk.location else - l_uri := percent_encoder.percent_decoded_string (response.api.path_alias (response.node_api.node_path (a_node))) + l_uri := percent_encoder.percent_decoded_string (response.api.location_alias (response.node_api.node_path (a_node))) end ti.set_text_value (l_uri) ti.set_description ("Optionally specify an alternative URL path by which this content can be accessed. For example, type 'about' when writing an about page. Use a relative path or the URL alias won't work.") @@ -122,6 +122,9 @@ feature -- Forms ... else -- TODO: implement full path alias validation end + if attached a_response.api.location_alias (f_path_alias) as l_aliased_location then + fd.report_invalid_field ("path_alias", "Path is already aliazed to location %"" + l_aliased_location + "%" !") + end end end(?, response) ) diff --git a/src/service/cms_api.e b/src/service/cms_api.e index 217c6ff..771e705 100644 --- a/src/service/cms_api.e +++ b/src/service/cms_api.e @@ -305,6 +305,18 @@ feature -- Path aliases storage.unset_path_alias (a_source, a_alias) end + location_alias (a_source: READABLE_STRING_8): READABLE_STRING_8 + -- Location alias associated with `a_source' or the source itself. + do + Result := a_source + if attached storage.path_alias (Result) as l_path then + Result := l_path + if Result.starts_with ("/") then + Result := Result.substring (2, Result.count) + end + end + end + path_alias (a_source: READABLE_STRING_8): READABLE_STRING_8 -- Path alias associated with `a_source' or the source itself. do