?
avatar Bakual
Bakual
3 Nov 2016

Steps to reproduce the issue

When trying to implement custom fields into my extension I hit a road block when trying to do it in frontend editing. This happens if the context of the frontend edit (eg sermonspeaker.serieform) is different from backend (eg sermonspeaker.serie).
This is also the case for com_content (content.form vs content.article) but that case is handled by the fields plugin in its getParts method (https://github.com/joomla/joomla-cms/blob/staging/plugins/system/fields/fields.php#L600-L646) and thus it works.
It does two things:
1. First it has two hardcoded mappings:

$mapping = array(
    'com_users.registration' => 'com_users.user',
    'com_content.category'   => 'com_content.article',
);

That obviously needs to be removed as it will show that exact issue.

  1. It tries to lookup the context from the database if the second part is "form":
if ($parts[1] == 'form')
{
    // The context is not from a known one, we need to do a lookup
    // @todo use the api here.
    $db    = JFactory::getDbo();
    $query = $db->getQuery(true)
        ->select('context')
        ->from('#__fields')
        ->where('context like ' . $db->quote($parts[0] . '.%'))
        ->group(array('context'));
    $db->setQuery($query);
    $tmp = $db->loadObjectList();
    if (count($tmp) == 1)
    {
        $parts = FieldsHelper::extract($tmp[0]->context);
        if (count($parts) < 2)
        {
            return null;
        }
    }
}

While it is nice to do some sort of fallback lookup, this shouldn't be tied to a specific name of the second part. In our case, this currently solves the issue for com_content but wouldn't help my component since I have multiple items and the query would return 3 contexts.

Expected result

Being able to save custom fields in frontend for 3rd party extensions

Actual result

Custom fields aren't saved for 3rd parties in frontend if the front- and backend contexts don't match.

Additional comments

avatar Bakual Bakual - open - 3 Nov 2016
avatar joomla-cms-bot joomla-cms-bot - change - 3 Nov 2016
Labels Added: ?
avatar brianteeman brianteeman - change - 3 Nov 2016
Category com_fields
avatar laoneo
laoneo - comment - 7 Nov 2016

A way I can see is to introduce some FieldsHelper classes in a component where we can request the valid context like

class ContentFieldsHelper
{
    public static function getContext($context)
    {
         .....
    }
}

This class can also be used then for other issues like removing the com_fields code in com_categories.

avatar infograf768
infograf768 - comment - 7 Nov 2016

Note:
I found a way to use the custom field of type list or checkbox for the frontend display (I am not speaking of the form itself)

I had to override ROOT/components/com_fields/layouts/field/render.php
and, for example do, (where $field->rawvalue is the value of the param)

<?php if ($field->title === 'Signatures' && $field->rawvalue = 1 && $field->type === 'list') : ?>
    <?php echo JText::_('Using list params'); ?> // can be anything here
<?php else : ?>
    <dd class="field-entry <?php echo $class; ?>" id="field-entry-<?php echo $field->id; ?>">
        <span class="field-label"><?php echo htmlentities($label); ?>: </span>
        <span class="field-value"><?php echo $value; ?></span>
    </dd>
<?php endif; ?>

Is that the way to do it?

avatar Bakual
Bakual - comment - 7 Nov 2016

@infograf768 Please keep this PR on topic. It's about frontend editing (form), not about the display of the field in an item.

@laoneo I was thinking the same. If we go the route with a helper it would also be simple to create an own backend UI for com_fields as you could get the valid contexts from the helper. No need for the extensions to add field and field group links to their sidebar. They still could provide those, but it wouldn't be needed.
What I would do is create a method getContexts which returns an array of possible contexts and it's mapping. Something along the lines you have in the plugin: https://github.com/joomla/joomla-cms/blob/staging/plugins/system/fields/fields.php#L604-L607.

avatar laoneo
laoneo - comment - 22 Nov 2016

Can be closed as we have a PR #12968.

avatar Bakual Bakual - change - 22 Nov 2016
Status New Closed
Closed_Date 0000-00-00 00:00:00 2016-11-22 10:32:54
Closed_By Bakual
avatar Bakual Bakual - close - 22 Nov 2016

Add a Comment

Login with GitHub to post a comment