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

@@ -0,0 +1,44 @@
note
description: "[
Information related to content or taxonomy entity in a taxonomy container.
Mainly used to build list of contents/entities associated with a term.
]"
date: "$Date$"
revision: "$Revision$"
class
CMS_TAXONOMY_ENTITY
inherit
COMPARABLE
create
make
feature {NONE} -- Initialization
make (a_content: CMS_CONTENT; a_date: DATE_TIME)
-- Build Current information from `a_content' dated by `a_date'.
do
content := a_content
date := a_date
end
feature -- Access
content: CMS_CONTENT
-- Content of the entity.
date: DATE_TIME
-- Date, usually related to last modification.
feature -- Comparison
is_less alias "<" (other: like Current): BOOLEAN
-- Is current object less than `other'?
do
Result := date < other.date
end
end

View File

@@ -0,0 +1,89 @@
note
description: "Container of entity associated with taxonomy term."
date: "$Date$"
revision: "$Revision$"
class
CMS_TAXONOMY_ENTITY_CONTAINER
inherit
ITERABLE [CMS_TAXONOMY_ENTITY]
create
make
feature -- Initialization
make (a_taxo_info: like taxonomy_info; a_limit: NATURAL_32; a_date: detachable DATE_TIME; a_type: detachable READABLE_STRING_8)
do
taxonomy_info := a_taxo_info
limit := a_limit
date := a_date
content_type := a_type
create items.make (a_limit.to_integer_32)
end
feature -- Settings
limit: NATURAL_32
-- Maximum container size.
date: detachable DATE_TIME
-- Contents related to entities listed on `taxonomy_info'.
content_type: detachable READABLE_STRING_8
-- Filter by content type if not Void.
feature -- Access
taxonomy_info: LIST [TUPLE [entity: READABLE_STRING_32; typename: detachable READABLE_STRING_32]]
-- Associated information.
items: ARRAYED_LIST [CMS_TAXONOMY_ENTITY]
-- List of recent events.
count: INTEGER
-- Number of change items.
do
Result := items.count
end
feature -- Access
new_cursor: ITERATION_CURSOR [CMS_TAXONOMY_ENTITY]
-- <Precursor>
do
Result := items.new_cursor
end
feature -- Change
force (a_item: CMS_TAXONOMY_ENTITY)
-- Add `a_item'.
do
items.force (a_item)
end
feature -- Sorting
sort
-- Sort `items' from older, to newer.
do
item_sorter.sort (items)
end
reverse_sort
-- Sort `items' from newer to older.
do
item_sorter.reverse_sort (items)
end
feature {NONE} -- Implementation
item_sorter: QUICK_SORTER [CMS_TAXONOMY_ENTITY]
-- New change item sorter.
once
create Result.make (create {COMPARABLE_COMPARATOR [CMS_TAXONOMY_ENTITY]})
end
end

View File

@@ -68,9 +68,10 @@ feature -- HTTP Methods
local
l_page: CMS_RESPONSE
tid: INTEGER_64
l_typename: detachable READABLE_STRING_8
l_entity: detachable READABLE_STRING_32
s: STRING
l_contents: CMS_TAXONOMY_ENTITY_CONTAINER
ct: CMS_CONTENT
do
if
attached {WSF_STRING} req.path_parameter ("termid") as p_termid and then
@@ -83,38 +84,58 @@ feature -- HTTP Methods
if attached taxonomy_api.term_by_id (tid) as t then
-- Responding with `main_content_html (l_page)'.
create {GENERIC_VIEW_CMS_RESPONSE} l_page.make (req, res, api)
l_page.set_title (t.text)
create s.make_empty
l_page.set_page_title ("Entities associated with term %"" + l_page.html_encoded (t.text) + "%":")
if
attached taxonomy_api.entities_associated_with_term (t) as l_entity_type_lst and then
not l_entity_type_lst.is_empty
then
s.append ("<ul class=%"taxonomy-entities%">")
across
l_entity_type_lst as ic
loop
-- FIXME: for now basic implementation .. to be replaced by specific hook !
if attached ic.item.entity as e and then e.is_valid_as_string_8 then
l_entity := e.to_string_8
if attached ic.item.type as l_type and then l_type.is_valid_as_string_8 then
l_typename := l_type.to_string_8
else
l_typename := Void
end
if l_typename /= Void then
s.append ("<li class=%""+ l_typename +"%">")
if
l_typename.is_case_insensitive_equal_general ("page")
or l_typename.is_case_insensitive_equal_general ("blog")
then
s.append (l_page.link ({STRING_32} "" + l_typename + "/" + l_entity, "node/" + l_entity.to_string_8, Void))
end
s.append ("</li>%N")
create l_contents.make (l_entity_type_lst, 25, create {DATE_TIME}.make_now_utc, Void)
if attached api.hooks.subscribers ({CMS_TAXONOMY_HOOK}) as lst then
across
lst as ic
loop
if attached {CMS_TAXONOMY_HOOK} ic.item as h then
h.populate_content_associated_with_term (t, l_contents)
end
end
l_contents.sort
s.append ("<ul class=%"taxonomy-entities%">")
across
l_contents as ic
loop
ct := ic.item.content
s.append ("<li class=%""+ ct.content_type +"%">")
if attached ct.link as lnk then
l_page.append_link_to_html (lnk.title, lnk.location, Void, s)
end
if attached api.content_type_webform_manager_by_name (ct.content_type) as l_wfm then
l_wfm.append_content_as_html_to (ct, True, s, l_page)
end
s.append ("</li>%N")
end
s.append ("</ul>%N")
end
if not l_contents.taxonomy_info.is_empty then
check all_taxo_handled: False end
s.append ("<ul class=%"error%">Item(s) with unknown content type!")
across
l_contents.taxonomy_info as ic
loop
-- FIXME: for now basic implementation .. to be replaced by specific hook !
if attached ic.item.entity as e and then e.is_valid_as_string_8 then
l_entity := e
s.append ("<li>Entity %"")
s.append (api.html_encoded (e))
s.append ("%"")
if attached ic.item.typename as l_type and then l_type.is_valid_as_string_8 then
s.append (" {" + api.html_encoded (l_type) + "}")
end
s.append ("</li>")
end
end
s.append ("</ul>%N")
end
s.append ("</ul>%N")
else
s.append ("No entity found.")
end