-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Field calendar plugin #13638
Field calendar plugin #13638
Conversation
I have tested this item ✅ successfully on c02720d This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/13638. |
@Bakual wasn't able to get Time in Calendar-Plugin, default Value is |
Yep, that's the part with the formatting in frontend. I need a solution for that (probably a new parameter). @laoneo also raised a concern that we store data in a plugin property. I'm not so sure if it's an issue as we do a similar thing in the debug plugin. |
To me, that would be better solution compare to the current one. However, there are two things;
So if we have to introduce a new event like in this PR, maybe we could trigger new event after this line https://github.com/joomla/joomla-cms/blob/staging/libraries/legacy/model/admin.php#L1192 $dispatcher->trigger('onDataAfterSave', array($context, $table, $isNew, $data)); Or $dispatcher->trigger('onItemAfterSave', array($context, $table, $isNew, $data)); How do you think about it? |
Yes, that line. And no, there is no warning. PHP doesn't generate a warning if you call a method with to many arguments.
3rd parties need to trigger the onContent.... events anyway. Otherwise the fields plugin will not work. The plugin is already listening on several such events (including the onContentAfterSave one). So there will be no difference here. Only thing would be if the extension triggers the event in its own code, it will need to add $data to it as well. But they need to adapt their code to support fields anyway. The only way this can be an issue imho is when a 3rd party extension already passed additional arguments to that event. I don't know how probable that is but imho it's the risk of the 3rd party if he does that. I wouldn't add a new event right after the existing one. Either we add one in a place where there is currently none, or we adjust the existing one. |
Thanks, I didn't know that. I thought the number arguments must be equal.
The reason I suggested to add a new event is because I thought that add new parameter to event trigger will causes backward compatible issues with existing plugins. Now I know that It is OK to add new parameters to existing event trigger, I will be happy if you add $data to event_after_save at this line https://github.com/joomla/joomla-cms/blob/staging/libraries/legacy/model/admin.php#L1192 Maybe add $data to event_before_save trigger at this line as well https://github.com/joomla/joomla-cms/blob/staging/libraries/legacy/model/admin.php#L1171 |
I wasn't sure myself, had to try it and verify with StackOverflow 😄
Yeah, that was my thinking as well. Both events should have similar signatures. |
Great. I will test it when it is ready :) |
c02720d
to
55d40ac
Compare
@joomdonation Removed the new events (will probably do a separate PR for those) and adjusted the existing save events to pass also the validated data. |
$parts = FieldsHelper::extract($context); | ||
|
||
if (!$parts) | ||
if (!$data || !is_array($data) || empty($data['params'])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe the code in this line could be simplified a bit to
if (!is_array($data) || empty($data['params']))
Otherwise, it looks good to me. I will test the behavior tonight my time and update the test result in the issue tracker
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, will adjust
@@ -21,4 +21,4 @@ | |||
$value = implode(', ', $value); | |||
} | |||
|
|||
echo htmlentities($value); | |||
echo htmlentities(JHtml::_('date', $value, JText::_('DATE_FORMAT_LC4'))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO the date format needs to be the same as for the calendar form field (where it is in strftotime) otherwise it will be too confusing for the end user.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not something new with custom fields. That's how we deal with dates all over Joomla.
Only the formfield itself uses strtotime because that is what JavaScript understands. When we display the date in an item, we always use the language strings together with JHtml::_('date'). See for example the "Created" date:
<?php echo JText::sprintf('COM_CONTENT_CREATED_DATE_ON', JHtml::_('date', $displayData['item']->created, JText::_('DATE_FORMAT_LC3'))); ?>
(https://github.com/joomla/joomla-cms/blob/staging/layouts/joomla/content/info_block/create_date.php#L16)
I very like the approach. If there is a way to handle the formats consistently then the issue is solved properly. |
Not in 3.x for sure. Maybe in 4.0 if we get a way that the JavaScript code understands PHP date formats and we can break B/C with all existing forms. 😄 |
But then I would suggest that we offer in the custom field only the formats which are available for the front for the datepicker and and not a free text field. |
Yes, that needs improvement anyway.
And for the display part we can toggle between
I think that would actually solve most use cases without becoming overly complex. |
Absolutely, one with time and one without. |
10235c1
to
703aabd
Compare
@laoneo I have now replaced the What do you think? |
Why not just making a drop down with available the formats, for me there is no need to have a text field here as we are not supporting it anyway for the front end display. |
Can you please fix the conflicts, would love to see it in the first beta 😉 |
…lidation to more generic onBeforeDataValidation and deprecate old name.
…e need for onContentBeforeSave method
703aabd
to
5e7e0bd
Compare
Rebased and fixed conflict. |
* @return DOMElement | ||
* | ||
* @since __DEPLOY_VERSION__ | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation is wrong :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
huh? Codestyle didn't complain and it's inline with other places afaik. I likely copied it anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Bakual Same in raw view. GH bug?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah now I see what you mean. I thought you meant something with that specific line is wrong but it's the whole docblock. Fixed niw.
I have tested this item ✅ successfully on f3682a0 This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/13638. |
@franz-wohlkoenig can you please test it again, as there have been many changes since your latest test. Thanks! |
I have tested this item ✅ successfully on f3682a0 This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/13638. |
Well done everyone! |
Pull Request for Issue #13606 .
Currently, when you have a calendar field the timezone with each save the timezone is added/substracted from the date, resulting in a shift of the date/time with each save. This is especially bad if you only want to store the date plus have a negative timezone (eg New York), then the date shifts one day back with each save.
Also when the date is displayed in frontend, it is off by the timezone as well.
Main issue is that the calendar formfield expects the value stored as UTC and applies the timezone when shown in the form. But currently, the value isn't converted to UTC during save which results in that shift.
Also the timezone isn't applied when the value is shown in frontend.
Summary of Changes
JHtml::date
to show the date in frontend. This automatically applies the user timezone to the value.JText::_()
to show the date in a localised format.With this PR this format is hardcoded toAlso overrides are possible to change that format easily.DATE_FORMAT_LC4
which will only show the date. That likely needs to be improved but I'm not yet sure how. It's not directly in the scope of this PR and can be done later fine.format
parameter of the field is replaced with ashowtime
parameter. It will control if the time is displayed or not both in forms and when the item is shown in frontend. It takes translated format strings.Introduces a new plugin event "onAfterDataValidation". Also adds a new "onBeforeDataValidation" event and deprecates the existing "onUserBeforeDataValidation". Here I need input from @wilsonge as he initially created this event with New Plugin Event #10751. Imho the name of the event is misleading as it has nothing to do with com_users (it's a general event).During that new event, the fields plugin will take the validated fields data, store it in a private property and use it in the onContentAfterSave event to store it into database. The "onContentBeforeSave" method isn't needed anymore in the fields plugin.onContentBeforeSave
andonContentAfterSave
events so they not only pass the table object but also the validated data. The fields data can then be taken simply from that $data array. I'm sure other extensions will find that useful as well.Testing Instructions
Documentation Changes Required
The
newadjusted event needs to be documented on https://docs.joomla.org/Plugin/Events.