Extra Block Types (EBT) - New Layout Builder experience❗

Extra Block Types (EBT) - styled, customizable block types: Slideshows, Tabs, Cards, Accordions and many others. Built-in settings for background, DOM Box, javascript plugins. Experience the future of layout building today.

Demo EBT modules Download EBT modules

❗Extra Paragraph Types (EPT) - New Paragraphs experience

Extra Paragraph Types (EPT) - analogical paragraph based set of modules.

Demo EPT modules Download EPT modules

Scroll

Drupal 8 Load entity by field value

Drupal 8 Load entity by field value
, by
Drupal 8 Load entity by field value
1 answer
votes: 1374
Answer

You can achieve by using EntityFieldQuery.

For D8 EntityFieldQuery has been rewritten.

Drupal 8:

$query = \Drupal::entityQuery('entity_test');
$default_langcode_group = $query->andConditionGroup()
  ->condition('user_id', $properties[$default_langcode]['user_id'], '=', $default_langcode)
  ->condition('name', $properties[$default_langcode]['name'], '=', $default_langcode);
$langcode_group = $query->andConditionGroup()
  ->condition('name', $properties[$langcode]['name'], '=', $langcode)
  ->condition("$this->field_name.value", $field_value, '=', $langcode);
$result = $query
  ->condition('langcode', $default_langcode)
  ->condition($default_langcode_group)
  ->condition($langcode_group)
  ->sort('name', 'ASC', $default_langcode)
  ->execute();

How do I fetch the values of an entity's field?

$query = \Drupal::entityQuery('node')
    ->condition('status', 1)
    ->condition('changed', REQUEST_TIME, '<')
    ->condition('title', 'cat', 'CONTAINS')
    ->condition('field_tags.entity.name', 'cats');

$nids = $query->execute();