Skip to content

[com_fields] Store fields in 'com_fields' property instead of reusing 'params'#13353

Merged
rdeutz merged 2 commits intojoomla:stagingfrom
Bakual:ChangeParamsToComfields
Mar 10, 2017
Merged

[com_fields] Store fields in 'com_fields' property instead of reusing 'params'#13353
rdeutz merged 2 commits intojoomla:stagingfrom
Bakual:ChangeParamsToComfields

Conversation

@Bakual
Copy link
Copy Markdown
Contributor

@Bakual Bakual commented Dec 23, 2016

This decouples a part of #13182 since we don't seem to get an agreement there anytime soon 😄

Summary of Changes

  • Store fields in 'com_fields' property instead of reusing the already existing 'params'. This eliminates possible conflicts.
  • Show custom fields in frontend article edit using the joomla.edit.params JLayout.
  • Adjusted the JLayout to take a custom tab name so it is reusable better. If no tab name is specified it uses the current behavior ('myTab').

Testing Instructions

  • Test that you can still save values into custom fields both in frontend and backend.
  • Inspect the HTML code and see that the ID attribute of the field has changed from jform_params_alias to jform_com_fields_alias and the name from jform[params][alias] to jform[com_fields][alias].

Documentation Changes Required

None

@ralain
Copy link
Copy Markdown
Contributor

ralain commented Dec 23, 2016

I have tested this item ✅ successfully on c8ff6d1

(Assuming you mean jform[com_fields][alias])


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/13353.

@Bakual
Copy link
Copy Markdown
Contributor Author

Bakual commented Dec 24, 2016

(Assuming you mean jform[com_fields][alias])

Of course! Adjusted the PR description now 😄

@laoneo
Copy link
Copy Markdown
Member

laoneo commented Dec 24, 2016

I don't se the benefit for this change honestly? Params is made for custom fields, so why not reuse it?

@Bakual
Copy link
Copy Markdown
Contributor Author

Bakual commented Dec 24, 2016

Params is made for custom fields, so why not reuse it?

Because it's not made for custom fields. It's a groupd specified in many (if not most) extensions XML file to hold various item options.
That means in most cases there is already data in that group, and it's the reason you load the existing data, convert it, merge with com_fields data, process it, unset it and convert the original params data back. All while having the risk that we have conflicts with existing data.
Now if using our own group, we can eliminate the risk of having conflicts and don't need to convert and merge and convert back the existing data.

Comment thread plugins/system/fields/fields.php Outdated
// Load the item params from the request
// Load the fields data from the request
$data = JFactory::getApplication()->input->post->get('jform', array(), 'array');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Fetching the data from the post request was only done for some exception I can't remember actually. IMO the custom fields values should be fetched from the item which get saved and not from the post request. That looks for me wrong.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I haven't changed that specific line, only the comment tied to it.
May it be that the custom fields data has been sanitised and removed prior to that step and thus we need to fetch it again? I haven't looked closer at it when I did this PR.

Copy link
Copy Markdown
Member

@laoneo laoneo Dec 28, 2016

Choose a reason for hiding this comment

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

In most cases, the fields values are in $item->params which are validated by the form. The code is on line 68.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I had a look now, the line is needed.
The thing is that $item is a JTable object and thus only contains the data that is going to be stored into the respective database table. There is neither a params or com_fields property at this point. So we need to fetch the raw form data and take the custom fields out of it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

For contacts the $item->params property exists which holds the custom fields values. But you are right for articles not. What is missing here is the form validation when take it directly from the input.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

True that. I'd say it's out of scope of this PR as this behavior exists with or without this PR.

@ggppdk
Copy link
Copy Markdown
Contributor

ggppdk commented Dec 28, 2016

This PR is needed
Besides the obvious reason to avoid conflicts, there are more benefits

  • since anyway they need to be seperated from params array, why add them there in the first place,

thus avoid the extra step to find the custom fields inside the 'params' and then clean-up the 'params' array before DB save

  • it makes easier to reference / handle them inside form via JS

  • easier to apply "different" validation of them ... in future if needed

  • also logically it makes sense since the 'params' are mostly non-content, and 'com_fields' are mostly 'content' ...

@laoneo
Copy link
Copy Markdown
Member

laoneo commented Jan 26, 2017

We have conflicts here.

@Bakual Bakual force-pushed the ChangeParamsToComfields branch from 77c0799 to 66873f8 Compare January 26, 2017 08:29
@Bakual
Copy link
Copy Markdown
Contributor Author

Bakual commented Jan 26, 2017

Rebased and conflict solved.

@Bakual Bakual force-pushed the ChangeParamsToComfields branch from 66873f8 to 9ef4ae5 Compare February 2, 2017 20:33
@Bakual
Copy link
Copy Markdown
Contributor Author

Bakual commented Feb 2, 2017

Rebased and fixed conflicts (again)

Show custom fields in frontend article edit using the joomla.edit.params JLayout.
Adjusted the JLayout to take a custom tab name.
@Bakual Bakual force-pushed the ChangeParamsToComfields branch from 9ef4ae5 to 75444ec Compare February 26, 2017 21:06
@Bakual
Copy link
Copy Markdown
Contributor Author

Bakual commented Feb 26, 2017

Rebased and fixed conflicts once more

* @return boolean
*
* @since 3.7.0
*/
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please don't delete that code. It cleans up the items which do have a params attribute. Otherwise the value of the fields are saved in the params array of the item as well.

Copy link
Copy Markdown
Contributor Author

@Bakual Bakual Feb 27, 2017

Choose a reason for hiding this comment

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

The whole point of this PR is to not store the field data in the params property. So no, they aren't saved there since we don't populate it into params anymore. And thus that code isn't needed anymore. 😄

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yea true.

JHtml::_('formbehavior.chosen', '#jform_catid', null, array('disable_search_threshold' => 0));
JHtml::_('formbehavior.chosen', 'select');
$this->tab_name = 'com-content-form';
$this->ignore_fieldsets = array('image-intro', 'image-full', 'jmetadata', 'item_associations');
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe a stupid question but why did you add this line? :-)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Because the article form currently only renders a fixed set of fieldsets. But we need it to render all available fieldsets.
So I have changed it to it renders all except those which are already hardcoded rendered.

@coolcat-creations
Copy link
Copy Markdown
Contributor

Please tag me if ready to test :)


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/13353.

@Bakual
Copy link
Copy Markdown
Contributor Author

Bakual commented Mar 8, 2017

@coolcat-creations It is ready for quite some time already 😄

@ggppdk
Copy link
Copy Markdown
Contributor

ggppdk commented Mar 8, 2017

I will test too during weekend

@coolcat-creations
Copy link
Copy Markdown
Contributor

I have tested this item ✅ successfully on 2b5784c

@Bakual sorry i should have read my errormessage :-D Test successful!


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/13353.

@laoneo
Copy link
Copy Markdown
Member

laoneo commented Mar 9, 2017

I will also have a look over the weekend, somehow I have the feeling something is missing.

@laoneo
Copy link
Copy Markdown
Member

laoneo commented Mar 10, 2017

I have tested this item ✅ successfully on 2b5784c


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/13353.

@ghost
Copy link
Copy Markdown

ghost commented Mar 10, 2017

RTC as there are 2 successfully Tests?

@jeckodevelopment
Copy link
Copy Markdown
Member

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/13353.

@joomla-cms-bot joomla-cms-bot added the RTC This Pull Request is Ready To Commit label Mar 10, 2017
@jeckodevelopment jeckodevelopment added this to the Joomla 3.7.0 milestone Mar 10, 2017
@rdeutz rdeutz merged commit e72cb97 into joomla:staging Mar 10, 2017
@joomla-cms-bot joomla-cms-bot removed the RTC This Pull Request is Ready To Commit label Mar 10, 2017
@Bakual Bakual deleted the ChangeParamsToComfields branch March 10, 2017 22:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants