Drupal 8 ConfigEntityType Entity Query example

so you are using a ConfigEntityType in drupal 8 and you want to know how to do an entity query will you are in luck say you have defined a custom key in your MODULE / config /schema / your_entity.schema.yml file

example

    color:
      type: string
      label: 'color'

Now in your entity class (the one where you put

*@ConfigEntityType(
 *   id = "your_entity_type",

 /**
   * This is an Entity Query to get an array of Entity ids by color.
   *
   * @param string $color
   *   This is a color example blue, red.
   *
   * @return array
   */
  public static function loadByColor($color) {
    $query = \Drupal::entityQuery('your_entity_type');
    $query->condition('color', $color);
    $entity_ids = $query->execute();
    return $entity_ids;
  }

Category: