Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.3] Run content plugins on custom fields values #44233

Draft
wants to merge 4 commits into
base: 5.3-dev
Choose a base branch
from

Conversation

rdeutz
Copy link
Contributor

@rdeutz rdeutz commented Oct 11, 2024

In the extension development room someone asked, if content plugins replace custom fields values. The correct answer to the question is: It depends.

If you include a field with {fields x} then it can be be replaced, if the content plugins run in the right order. E.g. I made a text field and set it to {loadmoduleid 17}, if the content/field plugin runs before the content/loadmodules plugin then its gets replaced otherwise not.

If the fields is displayed with "Automatic Display" then it is never replaced.

This feels inconsistent.

I had the idea to add a prepare content parameter to the fields like we have this for a custom module. The we could control the replacement better. Opinions please?

Summary of Changes

I have added a new parameter "Prepare Content" to the custom fileds like we have it for a custom module. I made changes to the FieldsHelper and run content plugins when the parameter is set to yes. The default value for "Prepare Content" is no. This can have an effect to the site performance.

I am not sure if we should add this to the core so I will keep it as draft and let the maintainers make an decision.

Testing Instructions

  • Create a custom field text
  • Create an article and set the custom fields to {loadmoduleid x}; x must be the id of an existing module
  • Add some text to the article and add {field y}; y is the id of the created custom field
  • Set the article to featured
  • Go to the homepage
  • Now apply patch
  • Change the "Prepare Content" to yes

Actual result BEFORE applying this Pull Request

1C4FB475-E975-46EA-9D61-9EBB12565621

or when the ordering of the content plugins is fields -> loadmodules

203C23C9-A9A6-49BF-8C71-FFA39BBB75C9

Expected result AFTER applying this Pull Request

2C00FB79-8325-4960-B685-A06CC63799AA

Link to documentations

Please select:

  • Documentation link for docs.joomla.org:

  • No documentation changes for docs.joomla.org needed

  • Pull Request link for manual.joomla.org:

  • No documentation changes for manual.joomla.org needed

@joomla-cms-bot joomla-cms-bot added Language Change This is for Translators PR-5.3-dev labels Oct 11, 2024
@rdeutz rdeutz added the Feature label Oct 11, 2024
@rdeutz rdeutz marked this pull request as draft October 11, 2024 12:43
$subject = new stdClass;
$subject->text = $value;

$dispatcher->dispatch('onContentPrepare', new ContentPrepareEvent('onContentPrepare', ['com_content.fields', $subject]));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just use HTMLHelper::_('content.prepare', $value, '', 'blabla.context');, as it is done in:

($data['module'])->content = HTMLHelper::_('content.prepare', ($data['module'])->content, '', 'mod_custom.content');

and many other places.

Co-authored-by: Brian Teeman <brian@teeman.net>
@@ -53,6 +53,8 @@ COM_FIELDS_FIELD_ONLY_USE_IN_SUBFORM_LABEL="Only Use In Subform"
COM_FIELDS_FIELD_PLACEHOLDER_DESC="Placeholder text which will appear inside the field as a hint to the user for the required input."
COM_FIELDS_FIELD_PLACEHOLDER_LABEL="Placeholder"
COM_FIELDS_FIELD_PREFIX_LABEL="Prefix"
COM_FIELDS_FIELD_PREPARE_CONTENT_DESC="Optionally prepare the content with Joomla Content Plugins."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
COM_FIELDS_FIELD_PREPARE_CONTENT_DESC="Optionally prepare the content with Joomla Content Plugins."
COM_FIELDS_FIELD_PREPARE_CONTENT_DESC="Use Joomla Content Plugins to prepare the content."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants