manniru
1/31/2017 - 3:26 PM

Drupal 8.x Cheatsheet

Drupal 8.x Cheatsheet

Entity API

$node->field_MYFIELD->value;
$node->get(field_MYFIELD)->get(0)->get('value');

$node->field_MYFIELD->toArray();
$node->field_MYFIELD->isEmpty();
$node->field_MYFIELD->view();
$node->field_MYFIELD->getString();

$entity = Entity::load($id);
$entities = Entity::loadMultiple($ids);
$entity_id = $entity->id();
$bundle = $entity->bundle();

$node = $this->entityTypeManager->getStorage('node')->load($nid);
$node = Node::load($nid);

$entity_display = \Drupal::entityManager()->getViewBuilder('ENTITY_TYPE')->view($entity, 'VIEW_MODE');
$display_array = \Drupal::service('renderer')->render($entity_display);

Services

// Path alias
$current_path = \Drupal::service('path.current')->getPath();
$path_alias = \Drupal::service('path.alias_manager')->getAliasByPath($current_path);


Resources