- Issue created by @GarChris
- πΊπΈUnited States owenbush Denver, CO
Hey there,
I suspect, based on your versions, that this is actually the following core issue π Allow adding computed bundle fields in Views Fixed , that has been resolved for I think 10.2+ but not backported to 9.x
I think this old MR that was targeting the 9.5.x branch should still work for you:
https://git.drupalcode.org/project/drupal/-/merge_requests/2511.diff
- πΊπΈUnited States GarChris
Thanks for your quick response, Owenbush. I applied the the patch but still getting the error. Any other suggestion - really need to get this working?
- πΊπΈUnited States owenbush Denver, CO
Do you get this error on all pages or only on views pages? The patch I linked to fixes a bug when an inherited field is added to a view, because inherited fields are computed fields and Drupal core did not support computed bundle basefields in views until that patch merged.
But if you were not on a view page, then there may be something else at play. Can you give steps to recreate the bug?
Thanks.
- πΊπΈUnited States GarChris
All pages are affected.
Steps to reproduce:- Install the module - composer require 'drupal/recurring_events:^2.0'
- Everything works fine - able to add events
- Clear Cache
- Visit any page - "The website encountered an unexpected error. Please try again later."
Some background:
- Running Opigno LMS, which does not allow upgrading beyond current core version. It also has a calendar view with a "recur" field. Not sure if that has any impact.
- Site was upgraded from Drupal 8
- Possibility that it's trying to find a deleted view? Any way to check this?
- πΊπΈUnited States GarChris
I've been experimenting:
Installed a fresh copy of Drupal 9.5.11. Installed Recurring Events. Cleared cache. Everything works fine.
Installed a fresh copy of Drupal Opigno. Crashed as soon as I installed Recurring Events and cleared cache.Below is the section of code (in web/core/modules/views/src/EntityViewsData.php) that's triggering this error.
// Add any bundle fields defined in code. // @todo Here we are assuming that hard-coded bundle field definitions // extend BaseFieldDefinition, which is a common case. Revisit this logic // in https://www.drupal.org/project/drupal/issues/2930736. $storage_definitions = $this->entityFieldManager->getFieldStorageDefinitions($this->entityType->id()); foreach (BaseFieldStorageConfigWrapper::getFieldBundles($this->entityType->id()) as $field_name => $bundles) { $storage_definition = isset($storage_definitions[$field_name]) ? $storage_definitions[$field_name] : NULL; if (!$storage_definition->isBaseField() && $storage_definition instanceof BaseFieldDefinition) { $field_storage = BaseFieldStorageConfigWrapper::createFromBaseFieldDefinition($storage_definition); views_collect_field_view_data($field_storage, $data); } } return $data; }
If I comment out this portion
// if (!$storage_definition->isBaseField() && $storage_definition instanceof BaseFieldDefinition) { // $field_storage = BaseFieldStorageConfigWrapper::createFromBaseFieldDefinition($storage_definition); // views_collect_field_view_data($field_storage, $data); // } }
The error goes away. But I'm no coder so I don't know what to do from here. I greatly appreciate your help.
- πΊπΈUnited States GarChris
There is an error in the Opigno Calendar View that might be related. Posted an issue in the Opigno issue queue but posting here as well for additional context:
In /view/opigno_calendar/edit/page_week:SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'range_intersects '202426')) AND (("opigno_calendar_event_field_data"."status"...' at line 8: SELECT COUNT(*) AS "expression" FROM (SELECT 1 AS "expression" FROM "opigno_calendar_event_field_data" "opigno_calendar_event_field_data" LEFT JOIN "opigno_calendar_event__date_daterange" "opigno_calendar_event__date_daterange" ON opigno_calendar_event_field_data.id = opigno_calendar_event__date_daterange.entity_id AND opigno_calendar_event__date_daterange.deleted = :views_join_condition_0 LEFT JOIN "opigno_calendar_event__635d6bfb18" "opigno_calendar_event__635d6bfb18" ON opigno_calendar_event_field_data.id = opigno_calendar_event__635d6bfb18.entity_id WHERE ((DATE_FORMAT((opigno_calendar_event__date_daterange.date_daterange_value + INTERVAL -14400 SECOND), '%Y%v') range_intersects :opigno_calendar_event__date_daterange_date_daterange_value_year_week)) AND (("opigno_calendar_event_field_data"."status" = :db_condition_placeholder_0) AND (("opigno_calendar_event__635d6bfb18"."field_calendar_event_members_target_id" IS NULL) OR ("opigno_calendar_event__635d6bfb18"."field_calendar_event_members_target_id" = :db_condition_placeholder_1)))) "subquery"; Array ( [:opigno_calendar_event__date_daterange_date_daterange_value_year_week] => 202426 [:db_condition_placeholder_0] => 1 [:db_condition_placeholder_1] => 2 [:views_join_condition_0] => 0 )
- πΊπΈUnited States owenbush Denver, CO
This took a while to track down, but what is interesting about the error you get and referenced is that code is not actually in Drupal core yet.
It seems to be part of this issue π [PP-1] bundleFieldDefinitions() are not added in EntityViewsData Needs work in patches up to, and including, #28. But this code has changed since that patch (to get it to work with D10/11), and has not been merged to core.
So it seems like something somewhere is applying that patch to core, and that is inadvertently breaking this functionality.
Is that something in your composer.json file, or perhaps in one of the composer.json files associated with Opigno?
- πΊπΈUnited States GarChris
Thanks owenbush.
This gets very interesting. The offending code was supplied by a patch that I added https://www.drupal.org/files/issues/2021-11-09/2930736-44.patch β (from issue: EntityViewsData assumes BaseFieldDefinitions where it should use FieldDefinitionInterface π EntityViewsData assumes BaseFieldDefinitions where it should use FieldDefinitionInterface Needs work )The error is present without the patch.
the error persists with the patch.
The error goes away when a portion of the code supplied by the patch is commented out.Conclusion: Something in the patch effectively solves the problem, but is negated by the offending portion of the code.
Unfortunately I don't understand code enough to know what is effective and how to isolate it from the rest of the code.
- πΊπΈUnited States GarChris
Omitting this patch β (from EntityViewsData assumes BaseFieldDefinitions... π EntityViewsData assumes BaseFieldDefinitions where it should use FieldDefinitionInterface Needs work )
and Changing line 390
from:
if (!$storage_definition->isBaseField() && $storage_definition instanceof BaseFieldDefinition) {
to:
if ($storage_definition && !$storage_definition->isBaseField() && $storage_definition instanceof BaseFieldDefinition) {
Resolves the issue.Here's a patch generated by Cody for the above, but it does not apply (Hunk #1 FAILED at 390)
diff --git a/web/core/modules/views/src/EntityViewsData.php b/web/core/modules/views/src/EntityViewsData.php index xxxxxxx..yyyyyyy 100644 --- a/web/core/modules/views/src/EntityViewsData.php +++ b/web/core/modules/views/src/EntityViewsData.php @@ -390,7 +390,7 @@ class EntityViewsData implements EntityViewsDataInterface { $storage_definition = isset($storage_definitions[$field_name]) ? $storage_definitions[$field_name] : NULL; - if (!$storage_definition->isBaseField() && $storage_definition instanceof BaseFieldDefinition) { + if ($storage_definition && !$storage_definition->isBaseField() && $storage_definition instanceof BaseFieldDefinition) { $field_storage = BaseFieldStorageConfigWrapper::createFromBaseFieldDefinition($storage_definition); views_collect_field_view_data($field_storage, $data); }
I'd greatly appreciate any help with a patch.
- πΊπΈUnited States GarChris
I think I've got it (and learned a lot in the process):
diff --git a/web/core/modules/views/src/EntityViewsData.php b/web/core/modules/views/src/EntityViewsData.php index xxxxxxx..yyyyyyy 100644 --- a/web/core/modules/views/src/EntityViewsData.php +++ b/web/core/modules/views/src/EntityViewsData.php @@ -387,7 +387,7 @@ $storage_definitions = $this->entityFieldManager->getFieldStorageDefinitions($this->entityType->id()); foreach (BaseFieldStorageConfigWrapper::getFieldBundles($this->entityType->id()) as $field_name => $bundles) { $storage_definition = isset($storage_definitions[$field_name]) ? $storage_definitions[$field_name] : NULL; - if (!$storage_definition->isBaseField() && $storage_definition instanceof BaseFieldDefinition) { + if ($storage_definition && !$storage_definition->isBaseField() && $storage_definition instanceof BaseFieldDefinition) { $field_storage = BaseFieldStorageConfigWrapper::createFromBaseFieldDefinition($storage_definition); views_collect_field_view_data($field_storage, $data); }
Thank you @owenbush for your help. It would be great if this could be added as a patch on Drupal in case others experience the same issue.
- πΉπ³Tunisia achoura
achraf.noomane β made their first commit to this issueβs fork.
- Status changed to Fixed
3 months ago 3:34pm 9 October 2024 - π§π¬Bulgaria pfrenssen Sofia
Great that you were able to solve the issue @garchris! Marking as fixed.
Automatically closed - issue fixed for 2 weeks with no activity.