Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Proposal: Parent-Children Relationship of Plugins#7969

jrief started this conversation inGeneral
Discussion options

jrief
Oct 29, 2017
Collaborator

Preambel

We should rethink the way how to handle the methods to determine which Plugin is eligible to become a child of another plugin.

Currently, when we open the CMS in structure mode, the Placeholder and its attached Plugins know which plugins may be added as children to an existing plugin. This is determined by each plugin through its attributesparent_plugins andchild_plugins. These attributes may be eitherNone or a list of strings. In the former case, all plugins are allowed as parent/children,
whereas in the latter case, only the named plugins are eligible as parents/children.

This static assignment has some drawbacks

  1. In an ecosystem of plugins from different vendors, beforehand we don't know, who may want to become the child of a plugin from another vendor. This could cause one vendor having to add his plugin to the list of allowed children from another vendor.

  2. Computing the eligible parent-children relationships is time consuming. Thereforedjango-CMS caches this information internally, which removes the possibility to determine dynamically, for instance by evaluating the current context, which children plugins can be added to an existing plugin.

  3. In structure mode, when rendering a deep tree of plugins, each plugin comes with its own list of eligible children plugins. This can add many kilobytes of additional data to the payload, when transferring a CMS page in structure mode.

  4. This rigid system of parent-children relationships, does for instance not allow to add kinds of intermediate plugins, such as wrappers or logical segments.

Therefore I want to propose a different method to determine which plugins are allowed as children of another plugin. Instead of computing this list staticallybefore the CMS page is rendered, we should add a REST endpoint, which computes this relationship dynamically and based on the current context.

This list then is transferred from the server to the client and is used to render a list of possible
children plugins. The computation of this list should work as follows:

  • The plugin being asked for, iterates over all plugins registered in the pool.
  • It then invokes a method, sayallowed_as_child_of() for each of the plugins of the pool,
    passing its own instance and the current context.
  • Based on the given parameters, this method returns a boolean, which determines, whether a plugin can be added to the current plugin or not.

This computation can now be much more time consuming. This is because we only have to do it
whenever the user clicks on the+ symbol inside the plugin editor, rather than having
to do it for all plugins inside the pool. Even if such a computation requires 200 milliseconds,
since this it is part of the user's interaction, this would disturb.

Possible new Features

Plugin systems, which map the Bootstrap grid, usually encounter the following problem:

A row may be part of a container, and columns may be part of that row. An accordion, carousel,
panel and similar elements can either be children of the container, the row or the column.

Depending below which of these elements an accordion panel is placed, its own children then
shall either be either rows, columns or plain content. This means that whenever
allowed_as_child_of() of an element is invoked, that method could check its potential
parent element, and if that does not contribute to the Bootstrap's grid structure (such as said
accordion, carousel, panel, etc.) it can go up a further level in the tree.

This feature would also make it possible to allow plugins depending on the siblings context.

Backwards Compatibility

Since we don't need the complicated caching functionality anymore, I even believe that it
reduces the amount of code. By adding an overridable methodallowed_as_child_of() to the
base classCMSPluginBase, this feature could even be implemented in a backward compatible
manner. This method then just would have to examine the plugin's attributeparent_plugins
and the attribute of its ancestorchild_plugins to determine whether it is allowed of
being added or not.

Implementation

In case thedjango-CMS community agrees on this proposal, I will implement this feature so
that it is available in a future major release. With this in mind, I'd like to open a discussion
about it.

You must be logged in to vote

Replies: 3 comments

Comment options

Hello@jrief,
Thanks for your proposal.
The google groups are still active and should be used for feature requests.
I've moved this tohttps://groups.google.com/forum/#!topic/django-cms-developers/vtsdrMWnUFA

You must be logged in to vote
0 replies
Comment options

jrief
Jul 26, 2024
Collaborator Author

@fsbraun this was the discussion I was talking about in our biweekly meeting today.

You must be logged in to vote
0 replies
Comment options

fsbraun
Jul 26, 2024
MaintainerSponsor

@jrief I see three parts to your proposal.

  1. More flexible rules, e.g., rules for grandparents.
  2. Dynamic rules, e.g., dependent on the current context.
  3. Time of data transfer: With the structure board for all existing plugins or fetch them on demand by plugin

Regarding the first part, I just wanted to point out the plugin methodsget_parent_classes andget_child_classes which allow making the relationship more flexible based on theinstance of the plugin: Theinstance parameter allows access to parent or child plugins. djangocms-form-builder, for example, usesget_parent_classes to make sure that form elements can only be placed inside a form plugin, regardless of other "intermediate" plugins.

At first sight, I have some concerns regarding part two: The plugin tree is a data structure (in the Django model kingdom) that should not depend on the template context (which belongs to Django's template kingdom). The plugins should be able to respond to context on rendering, but the tree structure might be better off being independent of the context. (A change in context would render an existing plugin tree in the database "illegal" and any change made might not be reversible.)

One more thought on the complexity of pasting or moving plugins versus adding single plugins:

  • Adding a single plugin can be covered easily by more flexible rules: Simply call get_parent_classes and have the flexible rules be evaluated for a plugin instance.
  • When pasting or moving, the descendants of the plugin must be considered: Whileget_parent_classes of the pasted or moved plugin might be OK with its new position, now any descendant plugin might not be OK with its parent thanks to the change in tree structure. So the overall result depends on evaluating full subtrees - something which to my knowledge is not done today but would need to be implemented with this proposal.
You must be logged in to vote
0 replies
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
General
Labels
None yet
3 participants
@jrief@czpython@fsbraun
Converted from issue

This discussion was converted from issue #6110 on July 26, 2024 20:08.


[8]ページ先頭

©2009-2025 Movatter.jp