Apparently, in 7.x-2.9-beta1 the function date_entity_metadata_struct_getter was changed from 5 parameters, only two ($tem and $name) which makes sense, as none of the other parameters are use. That said, none of the subsequent calls were updated to fix this change.
However, in the next beta iteration, and it appears the main dev branch, the parameter update was reverted back to the original 5 parameter call, fixing the issue caused previously.
I'm curious as to which is going to be the definition going forward?
I've attached a quick beta1 patch for anyone interested.
Comments
Comment #1
damienmckennaThanks for the patch, we'll try to review it soon.
BTW when you upload a patch it helps to set the status to "needs review", that triggers the testbots and lets others know that there's something review.
Comment #3
steinmb commentedNever hurt cleaning up stuff :)
When does this code actually get used? Did not test it. I tried to make date_entity_metadata_struct_getter() more verbose and hopefully clearer. DateObject::constructor do this horrible thing where the constructor actually can return NULL. That is the reason for some of it. We should remove that part when the Class constructor is fixed. Do we have a issue on that?
Comment #5
steinmb commentedAh Did not have entity enabled in my sandbox #2123039: Default timezone setting mismatch in metadata wrapper integration -
Comment #6
chicagomom commentedTesting patch date_getter.patch-2397997-5.patch - was getting Undefined index: field in date_entity_metadata_struct_getter() (line 659) , now getting Illegal offset type in date_entity_metadata_struct_getter() (line 665).
Comment #7
steinmb commentedThank your for testing
That is interesting. How did you test? Grepping through the code and we should have changes all use of them. Do you have code that call this function directly?
The error indicate to me that
function date_entity_metadata_struct_getter($item, $name, $info)$name get a wrong data type. If we only had to support PHP 7 we could changed the parameter tofunction date_entity_metadata_struct_getter(array $item, string $name, array $info) {to enforce the datatypes and provide better error messages.Comment #8
chicagomom commentedI'm testing on the test env of one of our production sites (on Pantheon) that makes heavy use of date and its related metadata. Just viewing existing event nodes that have date info. Site default time zone is set to America/Chicago.
ETA: no custom code that calls this directly.
PhP 7.1.23 and Drupal 7.60.
ETA: This error is being generated when these tokens are used in the metatag entry for event nodes. This content type includes the capability for multiple dates:
[node:field-event-date:0:value]
[node:field-event-date:0:value:custom:Y-m-d\TH:i:sO]
(See https://www.drupal.org/project/date/issues/1103032 for use pattern confusion discussion.)
This pattern generates incorrect date/day output, but generates output, along with the above error.
Comment #9
chicagomom commentedMore info on metadata output for this:
Any node created with single date/time returns today's date using [node:field-event-date:0:value:custom:someformat].
Comment #10
chicagomom commentedMore testing results. Here's what I get.
Meta-tags for multi-date field with one date entered (start date, no end date), using Drupal 7.60 with default time zone set to America/Chicago (-0600) and single date entered 01/08/2019 - 7:00pm (that's 08 Jan 2019):
7.x-2.10
[node:field_event_date] works, returning date as formatted by display mode format specification for token
[node:field-event-date:0:value] works, returning 01/08/2019 - 7:00pm as Tue, 01/08/2019 - 7:00pm
[node:field-event-date:0:value:custom:Y-m-d\TH:i:sO] works, returning 01/08/2019 - 7:00pm as 2019-01-08T19:00:00-0600
7.x-2.11-beta1
[node:field_event_date] works, returning date as formatted by display mode format specification for token
[node:field-event-date:0:value] returns 01/08/2019 - 7:00pm as Wed, 01/09/2019 - 1:00am
[node:field-event-date:0:value:custom:Y-m-d\TH:i:sO] returns 01/08/2019 - 7:00pm as 2019-01-09T01:00:00-0600
7.x-2.11-beta1+patch
[node:field_event_date] works, returning date as formatted by display mode format specification for token
[node:field-event-date:0:value] returns nothing
[node:field-event-date:0:value:custom:Y-m-d\TH:i:sO] returns today’s date/time
The issues with 2.11-beta1 and the patch are the loss of the ability to accurately return only a portion of the entered date (eg year only), or return the entered date with a custom format, or return the second date in a multi-date entry.
Comment #11
damienmckennaYou might like to review #2921146: Entity metadata getter/setter ignores granularity too.
Comment #12
solideogloria commentedJust updated to 7.x-2.11 on a site (without any patches), and I'm getting the notices in #6. Using PHP 7.3.
The following would fix it:
Comment #13
damienmckennaI think if we can finish #2074457 we can then look at finishing this.
Comment #14
argiepiano commentedIt looks like #2074457: Error messages from date_entity_metadata_struct_getter() is already committed. The error reported here still persists after applying that patch. It seems like the proposed patch in #12 is a a good solution. Can we take a closer look at this?
Comment #15
maddentim commentedI am using the code from #12 on a site except I changed the else to be
Without it, my field times were off by the site's timezone offset... Not sure if this is right for all, but worked for me. Looking at would date_get_timezone_db() was doing, I always wanted it to return 'UTC'. In my case, when I debugged the error, I was seeing that the $info variable was not coming in with $info['field'] set to anything. I could not tell what was calling this function to begin with. This site has been around for a bit so maybe there is some bad data in the config in the field set up.
Comment #16
damienmckennaIt might also be worth adding more test coverage to this so we can verify we don't accidentally break anything.