Problem/Motivation
#3116128: Add an EntityViewsData handler for improved Views integration added reverse relationships for base entity_reference fields, but it would be great to have these reverse relationships added for bundle plugin provided entity_reference fields as well.
Steps to reproduce
This isn't a bug - but if you create a bundle entity_reference field referencing an entity type, then go to add a view for this entity type there is no "relationship" for the bundle field's host entity.
Proposed resolution
Find and include bundle plugin entity_reference fields before adding all of the reverse relationships.
Remaining tasks
Implement change
Add test (unsure if there is test coverage for this?)
User interface changes
N/A
API changes
N/A
Data model changes
N/A
| Comment | File | Size | Author |
|---|---|---|---|
| #13 | 3206703-13.patch | 2.42 KB | m.stenta |
| #12 | 3206703-12.patch | 2.49 KB | paul121 |
| #10 | interdiff_7-10.txt | 1.34 KB | m.stenta |
| #10 | 3206703-10.patch | 2.31 KB | m.stenta |
| #7 | 3206703-7.patch | 2.23 KB | paul121 |
Issue fork entity-3206703
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
paul121 commentedComment #4
paul121 commentedAdding a patch that includes the change from #3190436: EntityViewsData Column information not available for computed entity reference fields. The two patches are conflicting and we need both of them for farmOS
Comment #5
paul121 commented@m.stenta and I discovered an odd bug pertaining to these bundle plugin reverse relationships while installing a module. TLDR; I added a commit that fixes the installation issue, although for the specific error we encountered, this still requires modules/site builders to rebuild Views Data sometime after installing a module in order for bundle field reverse relationships to be created for views.
When installing a module that provided an entity reference bundle field named
data_streamwe got this error:It was odd because this error only happened depending some of the time, depending on the order other modules were installed with farmOS. After a long chase hunting down module dependencies, we realized this error only happens when installing this module *after* another module that provides some special views - the issue doesn't seem to be that the module provides views, but these views had a CSV export display. While installing our module, for some reason, the views data was re-built *before* the bundle entity reference field was actually created in the DB. The way the EntityViewsData reverse relationship works, an error is thrown when looking for the entity reference field's table name (code)
Investigating further with a debugger it seems to make sense why this is happening - I could see the views data be rebuilt as part of the router rebuild - which doesn't happen on every install! This is why the CSV export display seems to be an important piece. It's not only that the view has a path, but something else to do with the display mode perhaps... (code)
The Entity module installs bundle field definitions in its implementation of
hook_modules_installed(). Looking at the coreModuleInstaller->install()service, this hook *is the very last thing* to be called (code). This is the root of the issue - bundle fields being installed last. It doesn't seem like there's a good way for the entity module to hook in earlier to this process... one option would be for each module to implementhook_installand call theentity.bundle_plugin_installerservice at that time.This all goes to show the need for bundle fields in core! It seems like this would be resolved if bundle fields were installed at the same time as base fields by core.
Comment #6
paul121 commentedReroll of the patch from #4 to include this fix.
Comment #7
paul121 commentedOops, had a typo in this last patch,
$field->isComputed()should have been$field_definition->isComputed().Comment #8
m.stentaWe may have discovered another case where this patch causes the
Table information not available for the '[field-name]' field.error to occur.Discovered here: https://farmos.discourse.group/t/is-it-possible-to-use-custom-fields-and...
Although, it's actually happening for *base* fields, not *bundle* fields in this case... so maybe it's not related. Requires further digging...
Tl;dr: attempting to add a new base field to an entity via
hook_entity_base_field_info()(https://github.com/jgOhYeah/farmOS/blob/5bc149c3e86d79e5d6ca089b51413a30...), along with an implementation ofhook_post_update_NAME()to create the field (https://github.com/jgOhYeah/farmOS/blob/5bc149c3e86d79e5d6ca089b51413a30...), the following error occurs when loading update.php (it works fine viadrush updb):It seems that simply going to
update.phpcauses the Views definitions to be rebuilt, which then attempts to find the database table name for the "owner" field, which hasn't been created yet (becauseupdate.phphasn't been run yet).Comment #9
m.stentaLooking closer, the changes to the patch that @paul121 introduced in #5 above work to prevent that error for *bundle* fields, but they do not cover *base* fields.
However, this is NOT the fault of this patch. The same issue would probably happen without it. Still, since we fix the issue for bundle fields in this patch then perhaps we should also fix it for base fields as well.
Comment #10
m.stentaOk this turned out to be a simple fix, thanks to @paul121's earlier fix, which was easy to replicate for base fields. :-)
Attached is an updated patch, along with an interdiff.
(I also updated some whitespace in the patch to use proper indentations, which you can also see in the interdiff.)
This allowed me to use
update.phpto create the new base field successfully!Comment #11
m.stenta#3190436: EntityViewsData Column information not available for computed entity reference fields has been merged so we need to re-roll this patch.
Comment #12
paul121 commentedOkay, I've rebased this on 8.x-1.5 and added two new commits to account for the changes in #10 and a relevant change from #3190436: EntityViewsData Column information not available for computed entity reference fields to use
hasCustomStorage()Including a patch file we can use for farmOS.
Comment #13
m.stentaRebased against the PHPStan error fixes that were applied in #3615092: missing CacheableMetadata parameter adn PHPStan errors, and re-rolled the patch.