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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

d.novikov created an issue. See original summary.

d.novikov’s picture

borisson_’s picture

Status: Needs review » Needs work

Is this processor useful at all for those kinds of fields? I'd prefer to throw a hard error instead I think.

Something like:

if (!$field->getDatasourceId()) {
  throw new InvalidConfigurationException("This field has no datasource, so there's no valid use for this processor");
}

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?

d.novikov’s picture

@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.

borisson_’s picture

I have no idea how to solve this. I'll ask drunken monkey for help.

drunken monkey’s picture

The 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.

borisson_’s picture

Status: Needs work » Needs review
FileSize
1.27 KB

I agree with @drunken monkey, we could only do an educated guess. I prefer the exception.

borisson_’s picture

Title: ListItemProcessor::build() failing when field datasource is empty. » Make ListItemProcessor::build() throw an exception when no datasource is available
Nick_vh’s picture

Status: Needs review » Reviewed & tested by the community

  • borisson_ committed d77805a on 8.x-1.x
    Issue #2829636 by d.novikov, borisson_: Make ListItemProcessor::build()...
borisson_’s picture

Status: Reviewed & tested by the community » Fixed

Committed, thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.