Skip to Main Content
Drupal 8 Module Development - Second Edition
book

Drupal 8 Module Development - Second Edition

by Daniel Sipos
March 2019
Intermediate to advanced content levelIntermediate to advanced
580 pages
15h 3m
English
Packt Publishing
Content preview from Drupal 8 Module Development - Second Edition

Reading entities

So, we have our entity loaded and we can now read its data. For content entities, this is where the TypedData knowledge comes into play. Before we look at that, let's see quickly how we can get the data from configuration entities. Let's inspect the Article NodeType for this purpose:

/** @var \Drupal\node\Entity\NodeType $type */$type = \Drupal::entityTypeManager()->getStorage('node_type')->load('article');

The first and simplest thing we can do is inspect the individual methods on the entity type class. For example, NodeType has a getDescription() method which is a handy helper to get the description field:

$description = $type->getDescription(); 

This is always the best way to try to get the field values of configuration ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Drupal 8 Module Development

Drupal 8 Module Development

Daniel Sipos
Learning Drupal 8

Learning Drupal 8

Rain Michaels
Mastering Drupal 8

Mastering Drupal 8

Chaz Chumley, William Hurley

Publisher Resources

ISBN: 9781789612363Supplemental Content