After upgrading to 7.x-2.11, I get the following errors when rendering in a view the value or value2 of a date field indexed with search_api (available in the view e.g. as "Birthdate: start date (indexed)" field):
Notice: Undefined index: field in date_entity_metadata_struct_getter() (Zeile 676 von /var/www/drupal/sites/all/modules/contrib/date/date.module).
Notice: Trying to access array offset on value of type null in date_entity_metadata_struct_getter() (Zeile 676 von /var/www/drupal/sites/all/modules/contrib/date/date.module).
#2123039: Default timezone setting mismatch in metadata wrapper integration introduced changes to date_entity_metadata_struct_getter():
- $timezone_db = !empty($item['timezone_db']) ? $item['timezone_db'] : 'UTC';
+ $timezone_db = date_get_timezone_db($info['field']['settings']['tz_handling']);
The problem here is that for these fields, there is no $info['field'] available, $item['timezone_db'] is though. So it works with the code from 7.x-2.10, but not with 7.x-2.11.
However, $info['parent']['info']['field']['settings']['tz_handling'] exists.
I don't know who should provide the field data here, search_api or entity, but maybe date should consider that the field data might not be available.
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | Screen Shot 2021-03-17 at 2.35.11 PM.png | 67.76 KB | jplana |
| #3 | date-undefined_index_field-3202888-3.patch | 849 bytes | ronino |
Comments
Comment #2
damienmckennaThis should be fixed in #2074457.
Comment #3
ronino commentedWhile #2074457: Error messages from date_entity_metadata_struct_getter() is about
$item[$name]not being set, this is about$info['field']. This is not related.The attached patch takes a first try to use the new behavior to determine timezone data if $info['field'] is given, otherwise it uses 2.10's way.
Comment #4
ronino commentedOn reproducibility: The notices are triggered only for date fields the subfields value and value2 of which have been indexed by search_api individually (listed at /admin/config/search/search_api/index/[index]/fields like "field_some_date:value", "...:value2" and such). They're not triggered for date fields that have been indexed as a whole (listed as "field_some_date2").
Comment #5
jplana commented+RTBC I can confirm the patch fixes the problem. Also worth noting that I agree with @Ronino, this issue is unrelated with #2074457
Reproducibility: We were able to reproduce it without using search_api. In our case there was a warning wall in an entity form with multiple date fields.
Comment #6
joelpittetYes, this is that issue I was mentioning in #2123039-46: Default timezone setting mismatch in metadata wrapper integration
RTBC++
Comment #7
jplana commentedJust to add a bit more context:
The date.module expect the field to have defined timezone settings, but this is an optional field setting, that will only show up if the field has time (hours, minutes, seconds). Attached screenshot to clarify.
Comment #8
damienmckennaComment #10
damienmckennaCommitted. Thank you.
Comment #11
.bert commentedThank you for this @Ronino!
This fixed an issue we saw related to tokens in Rules no longer converting for the timezone.