I am using Drupal 8. By retrieving an entity by Entity Query I am getting an array. How can I fetch directly the TID?
Right now I am doing the following:
public function getCommuneTidByPostalCode(int $postalCode) {
$commune = \Drupal::entityQuery('taxonomy_term')
->condition('field_zipcode', $postalCode)
->condition('vid', 'commune')
->execute();
if (!empty($commune)) {
return intval(key($commune));
}
}
Can I drop somehow this part?:
if (!empty($commune)) {
return intval(key($commune));
}