logo

Palette - Make it Colorful🎨

Palette - Visual Page Builder, no design degree required.

Live Demo Download Palette

Scroll

Drupal Get field value programmatically

22/02/2025, by Anonymous (not verified)
Permalink

You do not need to convert $entity into an array, this would simply work.

$entity->get('field_name')->getValue();

FYI : Using kint() from the devel_kint module will let you know all the available methods that could be used to access the object elements, so comparatively var_dump() is less helpful.

$node = \Drupal\node\Entity\Node::load($nid);
$title_field = $node->get('title');
$title = $title_field->value;

We don't really need to call get()

use Drupal\node\Entity\Node

$title = Node::load($nid)->title->value;