Refactored and update CMS hooks design. (Move from CMS_RESPONSE to CMS_API).

Moved content_types and content_type_webform_managers from CMS_RESPONSE to CMS_API.
Updated the way to output content (node, ...) to html page.
   See CMS_CONTENT_TYPE_WEBFORM_MANAGER.append_cointent_as_html_to (...).
   Added notion of "teaser" (short version of the content), as opposed to full content.
One can use CMS_API.html_encoder ... when possible, same for `formats', ...
Added bridge from CMS_MODULE_API to CMS_API's encoders.
Added new CMS_TAXONOMY_HOOK used to retrieve list of content associated with a specific term.
Moved up to CMS_RESPONSE a few features which was available only in specific descendants.

Added /taxonomy/term/{termid} implementation.
This commit is contained in:
2015-12-07 18:21:40 +01:00
parent ecbcb6a5cb
commit 6313007fbf
45 changed files with 691 additions and 357 deletions

View File

@@ -41,7 +41,6 @@ feature {NONE} -- Initialization
ct: CMS_PAGE_NODE_TYPE
do
-- Initialize node content types.
create content_type_webform_managers.make (1)
create ct
--| For now, add all available formats to content type `ct'.
across
@@ -50,7 +49,7 @@ feature {NONE} -- Initialization
ct.extend_format (ic.item)
end
add_node_type (ct)
add_content_type_webform_manager (create {CMS_PAGE_NODE_TYPE_WEBFORM_MANAGER}.make (ct))
add_node_type_webform_manager (create {CMS_PAGE_NODE_TYPE_WEBFORM_MANAGER}.make (ct, Current))
end
feature {CMS_MODULE} -- Access nodes storage.
@@ -106,31 +105,16 @@ feature -- Content type
feature -- Content type webform
content_type_webform_managers: ARRAYED_LIST [CMS_CONTENT_TYPE_WEBFORM_MANAGER]
content_type_webform_managers: ARRAYED_LIST [CMS_CONTENT_TYPE_WEBFORM_MANAGER [CMS_CONTENT]]
-- Available content types
add_content_type_webform_manager (a_manager: CMS_CONTENT_TYPE_WEBFORM_MANAGER)
-- Register webform manager `a_manager'.
do
content_type_webform_managers.force (a_manager)
Result := cms_api.content_type_webform_managers
end
content_type_webform_manager (a_content_type: CMS_CONTENT_TYPE): detachable CMS_CONTENT_TYPE_WEBFORM_MANAGER
-- Web form manager for content type `a_content_type' if any.
local
l_type_name: READABLE_STRING_GENERAL
add_node_type_webform_manager (a_manager: CMS_NODE_TYPE_WEBFORM_MANAGER [CMS_NODE])
-- Register webform manager `a_manager'.
do
l_type_name := a_content_type.name
across
content_type_webform_managers as ic
until
Result /= Void
loop
Result := ic.item
if not l_type_name.is_case_insensitive_equal (Result.name) then
Result := Void
end
end
cms_api.add_content_type_webform_manager (a_manager)
end
node_type_webform_manager (a_node_type: CMS_CONTENT_TYPE): detachable CMS_NODE_TYPE_WEBFORM_MANAGER_I [CMS_NODE]

View File

@@ -9,7 +9,7 @@ class
inherit
CMS_MODULE
redefine
register_hooks,
setup_hooks,
initialize,
is_installed,
install,
@@ -25,6 +25,8 @@ inherit
CMS_RECENT_CHANGES_HOOK
CMS_TAXONOMY_HOOK
CMS_HOOK_EXPORT
CMS_EXPORT_NODE_UTILITIES
@@ -234,16 +236,17 @@ feature -- Access: router
feature -- Hooks
register_hooks (a_response: CMS_RESPONSE)
setup_hooks (a_hooks: CMS_HOOK_CORE_MANAGER)
-- <Precursor>
do
a_response.hooks.subscribe_to_menu_system_alter_hook (Current)
a_response.hooks.subscribe_to_block_hook (Current)
a_response.hooks.subscribe_to_response_alter_hook (Current)
a_response.hooks.subscribe_to_export_hook (Current)
a_hooks.subscribe_to_menu_system_alter_hook (Current)
a_hooks.subscribe_to_block_hook (Current)
a_hooks.subscribe_to_response_alter_hook (Current)
a_hooks.subscribe_to_export_hook (Current)
-- Module specific hook, if available.
a_response.hooks.subscribe_to_hook (Current, {CMS_RECENT_CHANGES_HOOK})
a_hooks.subscribe_to_hook (Current, {CMS_RECENT_CHANGES_HOOK})
a_hooks.subscribe_to_hook (Current, {CMS_TAXONOMY_HOOK})
end
response_alter (a_response: CMS_RESPONSE)
@@ -364,6 +367,51 @@ feature -- Hooks
end
end
populate_content_associated_with_term (t: CMS_TERM; a_contents: CMS_TAXONOMY_ENTITY_CONTAINER)
local
l_node_typenames: ARRAYED_LIST [READABLE_STRING_8]
nid: INTEGER_64
l_info_to_remove: ARRAYED_LIST [TUPLE [entity: READABLE_STRING_32; typename: detachable READABLE_STRING_32]]
do
if
attached node_api as l_node_api and then
attached l_node_api.node_types as l_node_types and then
not l_node_types.is_empty
then
create l_node_typenames.make (l_node_types.count)
across
l_node_types as ic
loop
l_node_typenames.force (ic.item.name)
end
create l_info_to_remove.make (0)
across
a_contents.taxonomy_info as ic
loop
if
attached ic.item.typename as l_typename and then
across l_node_typenames as t_ic some t_ic.item.same_string (l_typename) end
then
if ic.item.entity.is_integer then
nid := ic.item.entity.to_integer_64
if nid > 0 and then attached l_node_api.node (nid) as l_node then
if l_node.link = Void then
l_node.set_link (l_node_api.node_link (l_node))
end
a_contents.force (create {CMS_TAXONOMY_ENTITY}.make (l_node, l_node.modification_date))
l_info_to_remove.force (ic.item)
end
end
end
end
across
l_info_to_remove as ic
loop
a_contents.taxonomy_info.prune_all (ic.item)
end
end
end
export_to (a_export_id_list: detachable ITERABLE [READABLE_STRING_GENERAL]; a_export_parameters: CMS_EXPORT_PARAMETERS; a_response: CMS_RESPONSE)
-- Export data identified by `a_export_id_list',
-- or export all data if `a_export_id_list' is Void.

View File

@@ -1,33 +0,0 @@
note
description: "[
Html builder for content type `content_type'.
This is used to build webform and html output for a specific node, or node content type.
]"
date: "$Date$"
revision: "$Revision$"
deferred class
CMS_CONTENT_TYPE_WEBFORM_MANAGER
inherit
CMS_API_ACCESS
feature {NONE} -- Initialization
make (a_type: like content_type)
do
content_type := a_type
end
feature -- Access
content_type: CMS_CONTENT_TYPE
-- Associated content type.
name: READABLE_STRING_8
-- Associated content type name.
do
Result := content_type.name
end
end

View File

@@ -400,7 +400,7 @@ feature -- Forms ...
elseif a_node /= Void and then attached a_node.format as s_format and then attached response.api.format (s_format) as f_format then
f := f_format
else
f := response.formats.default_format
f := cms_api.formats.default_format
end
-- Update node with summary and body content
@@ -464,7 +464,7 @@ feature -- Forms ...
elseif a_node /= Void and then attached a_node.format as s_format and then attached response.api.format (s_format) as f_format then
f := f_format
else
f := response.formats.default_format
f := cms_api.formats.default_format
end
-- Update node with summary and content
@@ -476,69 +476,78 @@ feature -- Forms ...
feature -- Output
append_html_output_to (a_node: CMS_NODE; a_response: NODE_RESPONSE)
append_content_as_html_to (a_node: G; is_teaser: BOOLEAN; a_output: STRING; a_response: detachable CMS_RESPONSE)
-- <Precursor>
local
lnk: CMS_LOCAL_LINK
lnk: detachable CMS_LOCAL_LINK
hdate: HTTP_DATE
s: STRING
node_api: CMS_NODE_API
l_node_api: CMS_NODE_API
do
node_api := a_response.node_api
a_response.set_value (a_node, "node")
l_node_api := node_api
-- Show tabs only if a user is authenticated.
if attached a_response.user as l_user then
lnk := a_response.node_local_link (a_node, a_response.translation ("View", Void))
if
not is_teaser and then
a_response /= Void and then
attached a_response.user as l_user
then
lnk := a_node.link
if lnk /= Void then
lnk := a_response.local_link (a_response.translation ("View", Void), lnk.location)
else
lnk := a_response.local_link (a_response.translation ("View", Void), l_node_api.node_path (a_node))
end
lnk.set_weight (1)
a_response.add_to_primary_tabs (lnk)
if a_node.status = {CMS_NODE_API}.trashed then
create lnk.make ("Delete", node_api.node_path (a_node) + "/delete")
create lnk.make ("Delete", l_node_api.node_path (a_node) + "/delete")
lnk.set_weight (2)
a_response.add_to_primary_tabs (lnk)
elseif a_node.has_id then
-- Node in {{CMS_NODE_API}.published} or {CMS_NODE_API}.not_published} status.
create lnk.make ("Edit", node_api.node_path (a_node) + "/edit")
create lnk.make ("Edit", l_node_api.node_path (a_node) + "/edit")
lnk.set_weight (2)
a_response.add_to_primary_tabs (lnk)
if
node_api.has_permission_for_action_on_node ("view revisions", a_node, l_user)
l_node_api.has_permission_for_action_on_node ("view revisions", a_node, l_user)
then
create lnk.make ("Revisions", node_api.node_path (a_node) + "/revision")
create lnk.make ("Revisions", l_node_api.node_path (a_node) + "/revision")
lnk.set_weight (3)
a_response.add_to_primary_tabs (lnk)
end
if
node_api.has_permission_for_action_on_node ("trash", a_node, l_user)
l_node_api.has_permission_for_action_on_node ("trash", a_node, l_user)
then
create lnk.make ("Move to trash", node_api.node_path (a_node) + "/trash")
create lnk.make ("Move to trash", l_node_api.node_path (a_node) + "/trash")
lnk.set_weight (3)
a_response.add_to_primary_tabs (lnk)
end
end
end
create s.make_empty
s.append ("<div class=%"cms-node node-" + a_node.content_type + "%">")
s.append ("<div class=%"info%"> ")
a_output.append ("<div class=%"")
if is_teaser then
a_output.append (" cms-teaser")
end
a_output.append ("cms-node node-" + a_node.content_type + "%">")
a_output.append ("<div class=%"info%"> ")
if attached a_node.author as l_author then
s.append (" by ")
s.append (a_response.html_encoded (l_author.name))
a_output.append (" by ")
a_output.append (l_node_api.html_encoded (l_author.name))
end
if attached a_node.modification_date as l_modified then
s.append (" (modified: ")
a_output.append (" (modified: ")
create hdate.make_from_date_time (l_modified)
s.append (hdate.yyyy_mmm_dd_string)
s.append (")")
a_output.append (hdate.yyyy_mmm_dd_string)
a_output.append (")")
end
s.append ("</div>")
a_output.append ("</div>")
if
attached {CMS_TAXONOMY_API} a_response.api.module_api ({CMS_TAXONOMY_MODULE}) as l_taxonomy_api and then
a_response /= Void and then
attached {CMS_TAXONOMY_API} cms_api.module_api ({CMS_TAXONOMY_MODULE}) as l_taxonomy_api and then
attached l_taxonomy_api.vocabularies_for_type (content_type.name) as vocs and then not vocs.is_empty
then
vocs.sort
@@ -549,60 +558,43 @@ feature -- Output
attached l_taxonomy_api.terms_of_entity (content_type.name, a_node.id.out, ic.item) as l_terms and then
not l_terms.is_empty
then
s.append ("<ul class=%"taxonomy term-" + ic.item.id.out + "%">")
s.append (a_response.html_encoded (ic.item.name))
s.append (": ")
a_output.append ("<ul class=%"taxonomy term-" + ic.item.id.out + "%">")
a_output.append (l_node_api.html_encoded (ic.item.name))
a_output.append (": ")
across
l_terms as t_ic
loop
s.append ("<li>")
a_response.append_link_to_html (t_ic.item.text, "taxonomy/term/" + t_ic.item.id.out, Void, s)
s.append ("</li>")
a_output.append ("<li>")
a_response.append_link_to_html (t_ic.item.text, "taxonomy/term/" + t_ic.item.id.out, Void, a_output)
a_output.append ("</li>")
end
s.append ("</ul>%N")
a_output.append ("</ul>%N")
end
end
end
-- We don't show the summary on the detail page, since its just a short view of the full content. Otherwise we would write the same thing twice.
-- The usage of the summary is to give a short overview in the list of nodes or for the meta tag "description"
-- if attached a_node.summary as l_summary then
-- s.append ("<p class=%"summary%">")
-- if attached node_api.cms_api.format (a_node.format) as f then
-- append_formatted_output (l_content, f, s)
-- else
-- append_formatted_output (l_content, a_response.formats.default_format, s)
-- end
-- s.append ("</p>")
-- end
if attached a_node.content as l_content then
s.append ("<p class=%"content%">")
if attached node_api.cms_api.format (a_node.format) as f then
append_formatted_output (l_content, f, s)
else
append_formatted_output (l_content, a_response.formats.default_format, s)
if is_teaser then
if attached a_node.summary as l_summary then
a_output.append ("<p class=%"summary%">")
if attached cms_api.format (a_node.format) as f then
append_formatted_content_to (l_summary, f, a_output)
else
append_formatted_content_to (l_summary, cms_api.formats.default_format, a_output)
end
a_output.append ("</p>")
end
s.append ("</p>")
end
s.append ("</div>")
a_response.set_title (a_node.title)
a_response.set_main_content (s)
end
append_formatted_output (a_content: READABLE_STRING_GENERAL; a_format: CONTENT_FORMAT; a_output: STRING_8)
-- Format `a_content' with format `a_format'.
do
if a_content.is_valid_as_string_8 then
a_output.append (a_format.formatted_output (a_content.to_string_8))
else
a_format.append_formatted_to (a_content, a_output)
elseif attached a_node.content as l_content then
a_output.append ("<p class=%"content%">")
if attached cms_api.format (a_node.format) as f then
append_formatted_content_to (l_content, f, a_output)
else
append_formatted_content_to (l_content, cms_api.formats.default_format, a_output)
end
a_output.append ("</p>")
end
a_output.append ("</div>")
end
end

View File

@@ -10,16 +10,35 @@ deferred class
CMS_NODE_TYPE_WEBFORM_MANAGER_I [G -> CMS_NODE]
inherit
CMS_CONTENT_TYPE_WEBFORM_MANAGER
CMS_CONTENT_TYPE_WEBFORM_MANAGER [CMS_NODE]
rename
make as old_make
redefine
content_type
end
feature {NONE} -- Initialization
make (a_type: like content_type; a_node_api: CMS_NODE_API)
do
node_api := a_node_api
old_make (a_type)
end
feature -- Access
content_type: CMS_NODE_TYPE [G]
-- Associated content type.
cms_api: CMS_API
-- API for current instance of CMS.
do
Result := node_api.cms_api
end
node_api: CMS_NODE_API
-- Associated node API.
feature -- Query
has_valid_node_type (a_node: CMS_NODE): BOOLEAN
@@ -57,11 +76,18 @@ feature -- Node ...
feature -- Output
append_html_output_to (a_node: CMS_NODE; a_response: NODE_RESPONSE)
append_content_as_html_to_page (a_node: G; a_response: NODE_RESPONSE)
-- Append an html representation of `a_node' to response `a_response'.
require
has_valid_node_type (a_node)
deferred
local
s: STRING
do
create s.make_empty
a_response.set_value (a_node, "node")
a_response.set_title (a_node.title)
append_content_as_html_to (a_node, False, s, a_response)
a_response.set_main_content (s)
end
end

View File

@@ -10,7 +10,7 @@ inherit
CMS_NODE_TYPE_WEBFORM_MANAGER [CMS_PAGE]
redefine
content_type,
append_html_output_to,
append_content_as_html_to,
populate_form,
new_node,
update_node
@@ -102,27 +102,27 @@ feature -- Forms ...
parent_validation (a_response: NODE_RESPONSE; fd: WSF_FORM_DATA)
local
node_api: CMS_NODE_API
l_node_api: CMS_NODE_API
l_parent_id: INTEGER_64
nid: INTEGER_64
l_parent_node: detachable CMS_NODE
do
node_api := a_response.node_api
l_node_api := node_api
if attached fd.integer_item ("select_parent_node") as s_parent_node then
l_parent_id := s_parent_node.to_integer_64
else
l_parent_id := 0
end
if l_parent_id > 0 then
l_parent_node := node_api.node (l_parent_id)
l_parent_node := l_node_api.node (l_parent_id)
if l_parent_node = Void then
fd.report_invalid_field ("select_parent_node", "Invalid parent, not found id #" + l_parent_id.out)
else
nid := a_response.node_id_path_parameter
if
nid > 0 and then
attached node_api.node (nid) as l_node and then
node_api.is_node_a_parent_of (l_node, l_parent_node)
attached l_node_api.node (nid) as l_node and then
l_node_api.is_node_a_parent_of (l_node, l_parent_node)
then
fd.report_invalid_field ("select_parent_node", "Invalid parent due to cycle (node #" + nid.out + " is already a parent of node #" + l_parent_id.out)
end
@@ -137,50 +137,51 @@ feature -- Forms ...
feature -- Output
append_html_output_to (a_node: CMS_NODE; a_response: NODE_RESPONSE)
append_content_as_html_to (a_node: CMS_PAGE; is_teaser: BOOLEAN; a_output: STRING; a_response: detachable CMS_RESPONSE)
-- <Precursor>
local
s: STRING
node_api: CMS_NODE_API
l_node_api: CMS_NODE_API
lnk: CMS_LOCAL_LINK
do
node_api := a_response.node_api
Precursor (a_node, a_response)
if a_node.has_id and then not a_node.is_trashed then
if node_api.has_permission_for_action_on_node ("create", a_node, a_response.user) then
create lnk.make ("Add Child", "node/add/page?parent=" + a_node.id.out)
lnk.set_weight (3)
a_response.add_to_primary_tabs (lnk)
end
end
if attached a_response.main_content as l_main_content then
s := l_main_content
else
create s.make_empty
end
if attached {CMS_PAGE} a_node as l_node_page then
s.append ("<ul class=%"page-navigation%">")
if attached l_node_page.parent as l_parent_node then
s.append ("<li class=%"page-parent%">Go to parent page ")
s.append (a_response.link (l_parent_node.title, a_response.node_api.node_path (l_parent_node), Void))
s.append ("</li>")
end
if attached node_api.children (a_node) as l_children then
across
l_children as ic
loop
s.append ("<li>")
s.append (a_response.link (ic.item.title, a_response.node_api.node_path (ic.item), Void))
s.append ("</li>")
Precursor (a_node, is_teaser, a_output, a_response)
if not is_teaser then
l_node_api := node_api
if
a_response /= Void and then
a_node.has_id and then not a_node.is_trashed
then
if
l_node_api.has_permission_for_action_on_node ("create", a_node, a_response.user)
then
create lnk.make ("Add Child", "node/add/page?parent=" + a_node.id.out)
lnk.set_weight (3)
a_response.add_to_primary_tabs (lnk)
end
end
s.append ("</ul>")
end
a_response.set_main_content (s)
if
a_response /= Void and then
attached {CMS_PAGE} a_node as l_node_page
then
a_output.append ("<ul class=%"page-navigation%">")
if attached l_node_page.parent as l_parent_node then
a_output.append ("<li class=%"page-parent%">Go to parent page ")
a_output.append (a_response.link (l_parent_node.title, l_node_api.node_path (l_parent_node), Void))
a_output.append ("</li>")
end
if attached l_node_api.children (a_node) as l_children then
across
l_children as ic
loop
a_output.append ("<li>")
a_output.append (a_response.link (ic.item.title, l_node_api.node_path (ic.item), Void))
a_output.append ("</li>")
end
end
a_output.append ("</ul>")
end
end
end
end

View File

@@ -114,7 +114,7 @@ feature {NONE} -- Create a new node
if attached a_type.new_node (Void) as l_node then
-- create new node
f := new_edit_form (l_node, url (location, Void), "edit-" + a_type.name, a_type)
hooks.invoke_form_alter (f, fd, Current)
api.hooks.invoke_form_alter (f, fd, Current)
if request.is_post_request_method then
f.validation_actions.extend (agent edit_form_validate (?, b))
f.submit_actions.put_front (agent edit_form_submit (?, l_node, a_type, b))
@@ -144,7 +144,7 @@ feature {NONE} -- Create a new node
fd: detachable WSF_FORM_DATA
do
f := new_edit_form (A_node, url (location, Void), "edit-" + a_type.name, a_type)
hooks.invoke_form_alter (f, fd, Current)
api.hooks.invoke_form_alter (f, fd, Current)
if request.is_post_request_method then
f.validation_actions.extend (agent edit_form_validate (?, b))
f.submit_actions.put_front (agent edit_form_submit (?, a_node, a_type, b))
@@ -175,7 +175,7 @@ feature {NONE} -- Create a new node
do
if a_node.is_trashed then
f := new_delete_form (a_node, url (location, Void), "delete-" + a_type.name, a_type)
hooks.invoke_form_alter (f, fd, Current)
api.hooks.invoke_form_alter (f, fd, Current)
if request.is_post_request_method then
f.process (Current)
fd := f.last_data
@@ -206,7 +206,7 @@ feature {NONE} -- Create a new node
fd: detachable WSF_FORM_DATA
do
f := new_trash_form (a_node, url (location, Void), "trash-" + a_type.name, a_type)
hooks.invoke_form_alter (f, fd, Current)
api.hooks.invoke_form_alter (f, fd, Current)
if request.is_post_request_method then
f.process (Current)
fd := f.last_data

View File

@@ -42,15 +42,6 @@ feature -- Helpers
feature -- Helpers: cms link
user_local_link (u: CMS_USER; a_opt_title: detachable READABLE_STRING_GENERAL): CMS_LOCAL_LINK
do
if a_opt_title /= Void then
create Result.make (a_opt_title, user_url (u))
else
create Result.make (u.name, user_url (u))
end
end
node_local_link (n: CMS_NODE; a_opt_title: detachable READABLE_STRING_GENERAL): CMS_LOCAL_LINK
do
if attached n.link as lnk then
@@ -59,17 +50,12 @@ feature -- Helpers: cms link
Result := node_api.node_link (n)
end
if a_opt_title /= Void and then not Result.title.same_string_general (a_opt_title) then
create Result.make (a_opt_title, Result.location)
Result := local_link (a_opt_title, Result.location)
end
end
feature -- Helpers: html link
user_html_link (u: CMS_USER): like link
do
Result := link (u.name, "user/" + u.id.out, Void)
end
node_html_link (n: CMS_NODE; a_opt_title: detachable READABLE_STRING_GENERAL): like link
local
l_title: detachable READABLE_STRING_GENERAL
@@ -80,18 +66,10 @@ feature -- Helpers: html link
l_title := n.title
end
Result := link (l_title, node_api.node_path (n), Void)
end
feature -- Helpers: URL
user_url (u: CMS_USER): like url
require
u_with_id: u.has_id
do
Result := url ("user/" + u.id.out, Void)
end
node_url (n: CMS_NODE): like url
require
n_with_id: n.has_id

View File

@@ -71,7 +71,7 @@ feature -- Execution
attached node_api.node_type_for (l_node) as l_content_type and then
attached node_api.node_type_webform_manager (l_content_type) as l_manager
then
l_manager.append_html_output_to (l_node, Current)
l_manager.append_content_as_html_to_page (l_node, Current)
end
elseif revision > 0 then
set_main_content ("Missing revision node!")