Skip to content

Instantly share code, notes, and snippets.

@nkgokul
Created July 22, 2019 06:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nkgokul/d8dcbaf1ad0abe892d962346ca59d356 to your computer and use it in GitHub Desktop.
Save nkgokul/d8dcbaf1ad0abe892d962346ca59d356 to your computer and use it in GitHub Desktop.
Entity and Field Details
use Drupal\node\Entity\Node;
$entity = Node::load(1183);
$fields = array_keys($entity->getFieldDefinitions());
dpm($fields);
foreach($fields as $field_name) {
dpm("Field Name");
dpm($field_name);
dpm("--------------");
dpm("Field Value");
dpm($entity->get($field_name)->value);
dpm("--------------");
dpm("Target Id");
dpm($entity->get($field_name)->target_id);
dpm("--------------");
dpm("Array Keys of Entity");
dpm(array_keys((array)$entity->get($field_name)->entity));
dpm("#########################################################");
}
// More details on https://drupal.stackexchange.com/a/231314/4876. Checkout answer by Berdir
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment