Conversation
2807add to
a751655
Compare
|
@mrcasals nice approach 👍. We should definitely build this in a way that it doesn't become dramatic to generalize in the future. Maybe adding a scope when registering a content block might make the API more flexible? Something like: Decidim.content_blocks.register(:home_page, :global_stats) do
# ...
endOr even: Decidim.content_blocks[:home_page].register(:global_stats) do
# ...
end |
|
@josepjaume that's what I wanted feedback of. I think we don't have a use case right now where this could be useful except for the homepage, and abstracting and reusing the admin section is not that simple. Still, I'd go with the first suggestion. |
|
Yeah, I definitely understand the reasons behind it. But using this API makes the use case more explicit from the reader's point of view, and also will potentially prevent us from having to modify this part of the code when we extend it. |
c361021 to
c11a6cd
Compare
|
@josepjaume done! I've modified the PR description and the code docs accordingly. |
3fcb666 to
c586f73
Compare
19b7e66 to
e9f8ce9
Compare
|
Following @deivid-rodriguez's suggestion (#2476 (comment)), I'm gonna add a few things a send this PR for review. This PR adds the backbones for ContentBlocks, and uses them in the homepage. I need to add a migration to create the default content blocks for existing organizations, and create the default content blocks on organization registration. |
| render | ||
| end | ||
|
|
||
| delegate :current_organization, to: :controller |
There was a problem hiding this comment.
Maybe we can add this to Decidim::ViewModel?
There was a problem hiding this comment.
I won't do it by now as it might affect other cells.
| belongs_to :organization, foreign_key: :decidim_organization_id, class_name: "Decidim::Organization" | ||
|
|
||
| def manifest | ||
| Decidim.content_blocks.for(scope).find { |manifest| manifest.name.to_s == manifest_name } |
| t.string :manifest_name, null: false, index: true | ||
| t.string :scope, null: false, index: true | ||
| t.jsonb :options | ||
| t.datetime :published_at |
There was a problem hiding this comment.
Add an index here (I guess we're only showing the published ones)
There was a problem hiding this comment.
Maybe we need a combined index with decidim_organization_id, can you try an run an explain on the query to see which is better?
| # frozen_string_literal: true | ||
|
|
||
| module Decidim | ||
| class ContentBlockManifest |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
|
|
||
| <% if !translated_attribute(current_organization.description).blank? %> | ||
| <%= render partial: "decidim/pages/home/sub_hero" %> | ||
| <% Decidim::ContentBlock.where(organization: current_organization, scope: :homepage).where.not(published_at: nil).order(weight: :asc).each do |content_block| %> |
There was a problem hiding this comment.
Maybe move all these conditions to a scope? (Also, related to the index comment for the database)
| # content_block.cell "decidim/content_blocks/carousel_block" | ||
| # end | ||
| # | ||
| # You will probably want to register your content blocs in an initializer in |
I see, you're right about refactorings losing content. Your approach for this feature looks good! |
🎩 What? Why?
This PR adds the concept of "content blocks" to Decidim. As of now, content blocks are only used in the home page.
A content block is a sortable, configurable layout block registered by a Decidim module.
Differences with view hooks?
On a view hook you can only hook a partial. There's no possibility of manual configuration, and even though you can set a priority, hooked views in the same priority cannot get sorted.
Examples of content blocks usage
📌 Related Issues
📋 Subtasks
CHANGELOGentryContentBlocktoContentBlockManifestimages). DB columns:RegisterOrganizationcommand insystem)In later PRs: