1

We're working on a custom module where we are creating participant content types programatically. We then have some queries to check for where a participant exists.

However although the field field_participant_email‎ exists and is defined, the below code results in the error InvalidArgumentException: Field field_participant_email is unknown.

$query = \Drupal::entityQuery('node');
$query->condition('type', 'participant');
$query->condition('field_participant_meeting', $meeting_id);
$query->condition('field_participant_email‎', $email);
$ids = $query->execute();

We've tried clearing cache, deleting and re-adding the field to no avail.

Does anyone have any suggestions or experiencing with this type of issue?

Much appreciated.

Update 1

For clarity, I've also checked the following:

  • checked the spelling of the field
  • deleted all the content types and reinstalled them through features
  • tried $query->condition('field_participant_email‎_value', $email);
  • tried $query->condition('field_participant_email‎.value', $email);

Update 2

Looking into the core/lib/Drupal/Core/Entity/Query/QueryInterface.php interface documentation, it seems that adding a condition against a custom field is not supported. This would explain why the error occurs. However I'm yet to find an alternative. I've also experienced the same error when trying to set the value of the field $node->set('field_participant_email‎', '[email protected]');.

1
  • From a technical level, there is no difference in custom fields - a field is a field, whether you created it yourself, or it was contributed by a module, or part of core, so your comment on the documentation isn't making sense.
    – Jaypan
    Commented May 9, 2022 at 3:07

1 Answer 1

0

The syntax for the field condition(s) is missing a column name (and potentially an operator)

$query->condition('field_participant_email‎.value', $email, '=');

Here is a useful tutorial on Entity Queries for Drupal 8 I always refer to:

The Drupal 8 version of EntityFieldQuery

1
  • Thanks for the response. This unfortunately did not resolve the issue and threw another exception. Having read that article you shared I suspect the dot notation works when navigating entity references. The new exception thrown btw was Fatal error: Call to a member function getColumns() on boolean in /var/www/html/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php on line 232
    – Greg G
    Commented Sep 4, 2018 at 16:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.