Score:1

FieldStorageConfigStorage::loadByProperties() with multiple conditions doesn't return any result

ng flag

Using FieldStorageConfigStorage::loadByProperties() with the entity_type and sid (from webforms) as conditions doesn't return any results. I can get a result if I run each of the conditions separately. Could be related to this issue, but I am not sure: https://www.drupal.org/project/drupal/issues/2917606. How can I fix this issue? If I need to write a repository service for this how do I do that?

My current code is the following one.

$storage = \Drupal::entityTypeManager()->getStorage('webform_submission');
$webform_submission = $storage->loadByProperties([
  'entity_type' => 'node',
  'sid' => $survey->get('field_webform_submission_id')->getString(),
]);

I am using Drupal 9.4.1 on PHP 8, using MySQL as database.

Jaypan avatar
de flag
What is `$storage` set to?
nschildre avatar
ng flag
I added it to the original post: $storage = \Drupal::entityTypeManager()->getStorage('webform_submission');
Jaypan avatar
de flag
Try `$survey->get('field_webform_submission_id')->value`.
4uk4 avatar
cn flag
`webform_submission` is a content entity. BTW, if you have the ID you don't need to query, you can just load the entity: `$storage->load($sid)`
apaderno avatar
us flag
As a side note, the storage class for *webform_submission* entities cannot load a different entity like a node. The shown code won't work.
nschildre avatar
ng flag
I tried that, but then getData(); doesn't get any data from $webform_submission.
nschildre avatar
ng flag
With ```$storage->load($sid)``` I ran into issues, but ```$survey->get('field_webform_submission_id')->value``` worked for me.
4uk4 avatar
cn flag
The second command gets the `$sid` you need for the first command. The problem is, your question asking about the field storage has nothing to do with either and it's unclear what you are asking about. So I'm voting to close the question.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.