2017 © Pedro Peláez
 

drupal-module easy-entity-reader

This Drupal 8 module helps developers access entity content.

image

thecodingmachine/easy-entity-reader

This Drupal 8 module helps developers access entity content.

  • Friday, January 19, 2018
  • by mouf
  • Repository
  • 7 Watchers
  • 2 Stars
  • 5,922 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 1 Versions
  • 10 % Grown

The README.md

Easy Entity Adapter

This package targets Drupal 8., (*1)

It offers developers a friendly way of accessing their entities., (*2)

Latest Stable Version Total Downloads Latest Unstable Version License Scrutinizer Code Quality Build Status Coverage Status, (*3)

Why?

Drupal has kind of a very verbose syntax to access entities., (*4)

Fed up of typing code like this?, (*5)

$entity->get('field_my_field')->getValue()[0]['value']

This package has the solution for you!, (*6)

How does it works?

This package registers in the Drupal container a new service: easy_entity_adapter.wrapper., (*7)

This service can "wrap" an entity into another object that is way easier to access. You can access values of the "wrapped" entity directly (using the array access notation)., (*8)

Here is a sample:, (*9)

// Let's assume you have a $entity variable containing an entity.

$wrapper = \Drupal::get('easy_entity_adapter.wrapper');

$easyEntity = $wrapper->wrap($entity);

// Now, you can access parts of your entity very easily.

$title = $easyEntity['title']; // $title is directly a string
$references = $easyEntity['my_custom_references']; // If the cardinality of the 'my_custom_references' is > 1, then the $references is automatically an array.
// Even better, referenced nodes are automatically fetched and converted into wrapped entities.

// So you can do something like:
$titleOfTheReferencedNode = $easyEntity['my_custom_references'][0]['title'];

Install

Simply use:, (*10)

composer require thecodingmachine/easy.entity.adapter

Twig integration

From Twig, you can wrap an entity into the adapter using the easy_entity function., (*11)

For instance:, (*12)

{{ easy_entity(node).title }}

The Versions

19/01 2018

1.0.x-dev

1.0.9999999.9999999-dev

This Drupal 8 module helps developers access entity content.

  Sources   Download

MIT

The Requires

 

The Development Requires

  • drupal/field_collection ~1.0
  • drupal/color_field ^2.0