Skip to main content
added 1 character in body
Source Link
No Sssweat
  • 31.6k
  • 14
  • 55
  • 91

An entity reference field, by definition, can only target one entity type so you can know what your target type is by calling up getSetting() on the field definition.

// Print the targeted entity type field.
$field = \Drupal\field\Entity\FieldStorageConfig::loadByName('node','field_tag''field_tags');
echo $field->getSetting('target_type');

Or better yet, use EntityReferenceFieldItemList::referencedEntities() to pull up the node's referenced entities and the associated data you need.

// Return an array of Entity objects referenced in the field.
$node->field_tags->referencedEntities();

An entity reference field, by definition, can only target one entity type so you can know what your target type is by calling up getSetting() on the field definition.

// Print the targeted entity type field.
$field = \Drupal\field\Entity\FieldStorageConfig::loadByName('node','field_tag');
echo $field->getSetting('target_type');

Or better yet, use EntityReferenceFieldItemList::referencedEntities() to pull up the node's referenced entities and the associated data you need.

// Return an array of Entity objects referenced in the field.
$node->field_tags->referencedEntities();

An entity reference field, by definition, can only target one entity type so you can know what your target type is by calling up getSetting() on the field definition.

// Print the targeted entity type field.
$field = \Drupal\field\Entity\FieldStorageConfig::loadByName('node','field_tags');
echo $field->getSetting('target_type');

Or better yet, use EntityReferenceFieldItemList::referencedEntities() to pull up the node's referenced entities and the associated data you need.

// Return an array of Entity objects referenced in the field.
$node->field_tags->referencedEntities();
added 1 character in body
Source Link
No Sssweat
  • 31.6k
  • 14
  • 55
  • 91

An entity reference field, by definition, can only target one entity type so you can know what your target type is by calling up getSetting() on the field definition.

// Print the targeted entity type field.
$field = \Drupal\field\Entity\FieldStorageConfig::loadByName('node','field_tag');
echo $field->getSetting('target_type');

Or better yet, use EntityReferenceFieldItemList::referencedEntities() to pull up the node's referenced entities and the associated data you need.

// Return an array of Entity objects referenced in the field.
$node->field_tag>field_tags->referencedEntities();

An entity reference field, by definition, can only target one entity type so you can know what your target type is by calling up getSetting() on the field definition.

// Print the targeted entity type field.
$field = \Drupal\field\Entity\FieldStorageConfig::loadByName('node','field_tag');
echo $field->getSetting('target_type');

Or better yet, use EntityReferenceFieldItemList::referencedEntities() to pull up the node's referenced entities and the associated data you need.

// Return an array of Entity objects referenced in the field.
$node->field_tag->referencedEntities();

An entity reference field, by definition, can only target one entity type so you can know what your target type is by calling up getSetting() on the field definition.

// Print the targeted entity type field.
$field = \Drupal\field\Entity\FieldStorageConfig::loadByName('node','field_tag');
echo $field->getSetting('target_type');

Or better yet, use EntityReferenceFieldItemList::referencedEntities() to pull up the node's referenced entities and the associated data you need.

// Return an array of Entity objects referenced in the field.
$node->field_tags->referencedEntities();
Source Link
Shawn Conn
  • 26.9k
  • 15
  • 49
  • 73

An entity reference field, by definition, can only target one entity type so you can know what your target type is by calling up getSetting() on the field definition.

// Print the targeted entity type field.
$field = \Drupal\field\Entity\FieldStorageConfig::loadByName('node','field_tag');
echo $field->getSetting('target_type');

Or better yet, use EntityReferenceFieldItemList::referencedEntities() to pull up the node's referenced entities and the associated data you need.

// Return an array of Entity objects referenced in the field.
$node->field_tag->referencedEntities();