Skip to main content

Drupal 8 Node Operations

Submitted by system on
Check if field exists in a node <?php $entity->hasField('abc'); ?> Get value of a field: <?php use Drupal\node\Entity\Node $title = Node::load($nid)->get('title')->value; $node = \Drupal::entityManager()->getStorage('node')->load($nid); //Another way to load ?> For User Added fields: <?php $terms = $node->get('abc')->getValue(); $terms = $node->abc->getValue(); ?> Get Nid from URL <?php $nid = \Drupal::routeMatch()->getRawParameter($node_id); ?> -- Link https://www.frobiovox.com/posts/2016/03/28/simplify-drupal-8-field-value-calls.html https://lakshminp.com/using-entity-api-drupal-8

Technologies