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
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions administrator/components/com_fields/forms/field.xml
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,18 @@
<option value="1">JYES</option>
<option value="0">JNO</option>
</field>
<field
name="prepare_content"
type="radio"
layout="joomla.form.field.radio.switcher"
label="COM_FIELDS_FIELD_PREPARE_CONTENT_LABEL"
description="COM_FIELDS_FIELD_PREPARE_CONTENT_DESC"
default="0"
richard67 marked this conversation as resolved.
Show resolved Hide resolved
filter="integer"
>
<option value="0">JNO</option>
<option value="1">JYES</option>
</field>
</fieldset>
<fieldset name="smartsearchoptions" label="COM_FIELDS_FIELD_SMARTSEARCHOPTIONS_HEADING">
<field
Expand Down
11 changes: 11 additions & 0 deletions administrator/components/com_fields/src/Helper/FieldsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace Joomla\Component\Fields\Administrator\Helper;

use Joomla\CMS\Event\Content\ContentPrepareEvent;
use Joomla\CMS\Event\CustomFields\AfterPrepareFieldEvent;
use Joomla\CMS\Event\CustomFields\BeforePrepareFieldEvent;
use Joomla\CMS\Event\CustomFields\GetTypesEvent;
Expand Down Expand Up @@ -173,6 +174,7 @@ public static function getFields(
/** @var DispatcherInterface $dispatcher */
$dispatcher = Factory::getContainer()->get(DispatcherInterface::class);
PluginHelper::importPlugin('fields', null, true, $dispatcher);
PluginHelper::importPlugin('content', null, true, $dispatcher);

$fieldIds = array_map(
function ($f) {
Expand Down Expand Up @@ -245,6 +247,15 @@ function ($f) {
$dispatcher->dispatch('onCustomFieldsAfterPrepareField', $eventAfter);
$value = $eventAfter->getValue();

if ($field->params->get('prepare_content') === 1) {
$subject = new \stdClass;
richard67 marked this conversation as resolved.
Show resolved Hide resolved
$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.


$value = $subject->text;
}

// Assign the value
$field->value = $value;
}
Expand Down
2 changes: 2 additions & 0 deletions administrator/language/en-GB/com_fields.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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."

COM_FIELDS_FIELD_PREPARE_CONTENT_LABEL="Prepare Content"
COM_FIELDS_FIELD_RENDER_CLASS_DESC="The class of the field container in the output."
COM_FIELDS_FIELD_RENDER_CLASS_LABEL="Display Class"
COM_FIELDS_FIELD_RENDEROPTIONS_HEADING="Display Options"
Expand Down