Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
When facet uses Search API field, build fails if the field does not have datasource. This might be the case when field is provided by Search API processor:
Drupal\Component\Plugin\Exception\PluginNotFoundException: The "" entity type does not exist. in Drupal\Core\Entity\EntityTypeManager->getDefinition() (line 133 of /home/dnovikov/workspace/filmportal8/docroot/core/lib/Drupal/Core/Entity/EntityTypeManager.php).
Suggested patch is attached.
Comment | File | Size | Author |
---|---|---|---|
#7 | 2829636-7.patch | 1.27 KB | borisson_ |
Comments
Comment #2
d.novikov CreditAttribution: d.novikov as a volunteer commentedComment #3
borisson_Is this processor useful at all for those kinds of fields? I'd prefer to throw a hard error instead I think.
Something like:
However, that might be a little overkill. Not sure. In what scenario is it useful to have this processor enabled when no datasource is available?
Comment #4
d.novikov CreditAttribution: d.novikov as a volunteer commented@borisson, for me it was a use-case when I needed to expose a computed base field (computed fields do not have datasource) to Search API, and switch between facet values/labels in UI. Maybe it can be done differently, I will be glad to hear your opinion.
Comment #5
borisson_I have no idea how to solve this. I'll ask drunken monkey for help.
Comment #6
drunken monkeyThe proposed solution doesn't seem much of an improvement – it would really just help you if that field is from a node, or by chance corresponds to a node field. It adds much more chaos than functionality, in my opinion.
If you want to make an educated guess of a datasource-independent field's option list/labels, you can try looking into the return value of
$field->getDataDefinition()
– I don't really know where to go from there, though. (I've been looking for a way to generically retrieve a field's option list from the definition myself, but it doesn't seem like that's possible anymore in Drupal 8.)@ d.novikov: Is there a way to get the options list from the data definition in your case? Maybe the Facets module (and others) could just define and suppport a generic way to set an options list (callback) there? That would seem to be the cleanest solution for this to me.
But it does sound like a pretty niche feature, so just saying you won't support such functionality (and throw an exception instead) also seems like a valid solution to me.
By the way, in any case, there is also
$field->getDatasource()->getEntityTypeId()
for getting the entity type – hard-coding the "entity:" prefix is not necessary and should be avoided for compatibility with other contrib modules that might add entity datasources.Comment #7
borisson_I agree with @drunken monkey, we could only do an educated guess. I prefer the exception.
Comment #8
borisson_Comment #9
Nick_vhComment #11
borisson_Committed, thanks!