After checking out the 8.x-2.x branch on a site that previously had 8.x-2.0-alpha3 installed, I got the following error when running drush cr, or visiting a page:
Error: Call to a member function getTargetEntityTypeId() on null in /var/www/drupalvm/drupal/web/modules/contrib/views_natural_sort/src/ViewsNaturalSortService.php on line 244
Stack trace:
#0 /var/www/drupalvm/drupal/web/modules/contrib/views_natural_sort/src/ViewsNaturalSortService.php(128): Drupal\views_natural_sort\ViewsNaturalSortService->getViewsBaseTable(NULL)
#1 /var/www/drupalvm/drupal/web/modules/contrib/views_natural_sort/views_natural_sort.views.inc(8): Drupal\views_natural_sort\ViewsNaturalSortService->getSupportedEntityProperties()
#2 /var/www/drupalvm/drupal/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(501): views_natural_sort_views_data_alter(Array, NULL, NULL)
#3 /var/www/drupalvm/drupal/web/core/modules/views/src/ViewsData.php(254): Drupal\Core\Extension\ModuleHandler->alter('views_data', Array)
#4 /var/www/drupalvm/drupal/web/core/modules/views/src/ViewsData.php(162): Drupal\views\ViewsData->getData()
#5 /var/www/drupalvm/drupal/web/core/modules/views/src/Plugin/Derivative/ViewsEnti in /var/www/drupalvm/drupal/web/modules/contrib/views_natural_sort/src/ViewsNaturalSortService.php, line 244
Checking out the 8.x-2.0-alpha3 tag again, the issue did not recur.
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | fatal-2931206-9.patch | 1.62 KB | sker101 |
| #2 | fatal-2931206-2.patch | 3.13 KB | malcomio |
Comments
Comment #2
malcomio commentedAdding a check to see if $fieldDefinition is not empty seems to address the issue - still need to do more testing to see if this change has any side-effects.
Comment #3
generalredneckYeah my first question would be why was it NULL in the first place. I'll see if I can reproduce on a new site install... with views_natural_sort_test installed. If not we need to see what field type causes that.
It's very possible that I'm in the middle of somethijng there too like trying to get text fields to work :p
Been a while so I can't say for sure
Comment #4
asak commentedI hit this error as well. The patch resolved the error, and I can see that the problematic field was from the video entity:
Notice: Undefined index: field_media_oembed_video in Drupal\views_natural_sort\ViewsNaturalSortService->getSupportedEntityProperties() (line 124 of modules/contrib/views_natural_sort/src/ViewsNaturalSortService.php).Comment #5
generalredneckI'll give that a shot.
Comment #6
imclean commentedIn support of #4, I did some debugging and noticed
$fieldConfigisnullfor the fieldfield_media_oembed_video.The problem is the field definitions for the entity type doesn't include that field. The field is attached to the
remote_videobundle of themediaentity type.The field definitions are obtained here:
See getBaseFieldDefinitions() documentation:
While the field
field_media_oembed_videois specific to the bundle, it may be considered a "configurable field", but I'm not sure. It can't be deleted so I'm not sure if that means it is configurable.Comment #7
sker101 commentedHi, I'm seeing the other error now after applying the patch.
It's one of my custom field from my node entity and it's happening whenever I try to save the one of the views or try to install site from config on our CI environment.
After looking into the codebase, what I don't get is it's trying to grab the field config of all the entity fields from the values returned by the method "getBaseFieldDefinitions" and which won't return the field config for custom fields like what comment #6 pointed out.
I created a patch that replace the method "getBaseFieldDefinitions" with "getFieldDefinitions" because the method "getFieldDefinitions" would return config for all fields including the custom fields. Also, the original method "getBaseFieldDefinitions" would only take one argument but it's currently passing two arguments, so I assumed "getFieldDefinitions" is the one that should be called here.
I also updated the logic a little bit based on the first patch, so it looks clearer in the patch file. The previous logic was just wrapping all the code inside an if statement but it created a lot of file diffs.
Comment #9
sker101 commentedOkay, it looks like we still need to use the "getBaseFieldDefinitions" method for entity types that don't have any bundles, for example, comment.
Here's the updated patch.
Comment #10
sker101 commentedComment #12
generalredneckThis worked out with my testing as well. making this as fix for the next release.