What's New in Drupal 8: Entity Field API
-
Upload
drupalizeme -
Category
Technology
-
view
426 -
download
4
Transcript of What's New in Drupal 8: Entity Field API
![Page 1: What's New in Drupal 8: Entity Field API](https://reader034.fdocuments.net/reader034/viewer/2022042611/58797c661a28ab6c358b4a0f/html5/thumbnails/1.jpg)
What’s New in Drupal 8Entity Field API
![Page 2: What's New in Drupal 8: Entity Field API](https://reader034.fdocuments.net/reader034/viewer/2022042611/58797c661a28ab6c358b4a0f/html5/thumbnails/2.jpg)
What We’re Talking About‣ How entities are used in Drupal 7 ‣ Improvements to the entity API ‣ Improvements to the field API ‣ Other new things that are made easier, or possible, by
these improvements ‣ What you can do to start learning now
![Page 3: What's New in Drupal 8: Entity Field API](https://reader034.fdocuments.net/reader034/viewer/2022042611/58797c661a28ab6c358b4a0f/html5/thumbnails/3.jpg)
Drupal 7 Entities & Fields‣ Introduced late in the development cycle–laid the
groundwork for consistency but comes up short ‣ Fields and properties are handled differently ‣ EntityFieldQuery is limited in functionality ‣ Enhancements in contributed entity module
![Page 4: What's New in Drupal 8: Entity Field API](https://reader034.fdocuments.net/reader034/viewer/2022042611/58797c661a28ab6c358b4a0f/html5/thumbnails/4.jpg)
Everything Is an Entity‣ Universal API for data CRUD ‣ All content is stored as entities ‣ Complex configuration is stored as entities ‣ Your data should be stored as entities
![Page 5: What's New in Drupal 8: Entity Field API](https://reader034.fdocuments.net/reader034/viewer/2022042611/58797c661a28ab6c358b4a0f/html5/thumbnails/5.jpg)
Entities‣ Entities are typed objects ‣ YourEntity implements EntityInterface ‣ EntityManager for interacting with entities of
any type ‣ Everything is a field
![Page 6: What's New in Drupal 8: Entity Field API](https://reader034.fdocuments.net/reader034/viewer/2022042611/58797c661a28ab6c358b4a0f/html5/thumbnails/6.jpg)
Fields‣ Base fields vs. bundle fields ‣ Consistent API for accessing field values ‣ Widgets & formatters work for all fields ‣ Chainable, and smart about relationships
![Page 7: What's New in Drupal 8: Entity Field API](https://reader034.fdocuments.net/reader034/viewer/2022042611/58797c661a28ab6c358b4a0f/html5/thumbnails/7.jpg)
// Drupal 7 print $node->field_name[LANGUAGE_NONE][0]['value'];
// Drupal 8 print $node->field_name->value; $author_name = $node->uid->entity->name->value;
Code Examples
![Page 8: What's New in Drupal 8: Entity Field API](https://reader034.fdocuments.net/reader034/viewer/2022042611/58797c661a28ab6c358b4a0f/html5/thumbnails/8.jpg)
// Drupal 7 $field = field_info_field($field_name); $instance = field_info_instance($entity_type, $field_name, $bundle); // Drupal 8 $field_definition = $entity->field_name->getFieldDefinition()
Code Examples
![Page 9: What's New in Drupal 8: Entity Field API](https://reader034.fdocuments.net/reader034/viewer/2022042611/58797c661a28ab6c358b4a0f/html5/thumbnails/9.jpg)
// Drupal 8 $node->field_name->value = 'Hello world'; $node->save();
Code Examples
![Page 10: What's New in Drupal 8: Entity Field API](https://reader034.fdocuments.net/reader034/viewer/2022042611/58797c661a28ab6c358b4a0f/html5/thumbnails/10.jpg)
Handlers‣ Entities represent a piece of data, handlers are
responsible for acting on that data ‣ Declared per entity type ‣ Use the defaults, or extend them for customizations
‣ Storage ‣ Forms
‣ Access control ‣ Listing
Handers are used for:‣ Rendering ‣ etc.
![Page 11: What's New in Drupal 8: Entity Field API](https://reader034.fdocuments.net/reader034/viewer/2022042611/58797c661a28ab6c358b4a0f/html5/thumbnails/11.jpg)
EntityQuery‣ Improved EntityFieldQuery ‣ No more propertyCondition() vs. fieldCondition(), just condition()
‣ Don't query the database, extend the storage handler and add your own methods
![Page 12: What's New in Drupal 8: Entity Field API](https://reader034.fdocuments.net/reader034/viewer/2022042611/58797c661a28ab6c358b4a0f/html5/thumbnails/12.jpg)
Translations‣ Native support for translation of all entity content ‣ Easily access translated values for an entire entity or
individual fields
$translation = $node->getTranslation('es');
// English title print $node->title->value; // Spanish title print $translation->title->value;
![Page 13: What's New in Drupal 8: Entity Field API](https://reader034.fdocuments.net/reader034/viewer/2022042611/58797c661a28ab6c358b4a0f/html5/thumbnails/13.jpg)
Typed Data API‣ Metadata about the data stored in a field ‣ Predictable and consistent representation ‣ Makes it easier for REST, Views, Tokens, etc. to
access data
![Page 14: What's New in Drupal 8: Entity Field API](https://reader034.fdocuments.net/reader034/viewer/2022042611/58797c661a28ab6c358b4a0f/html5/thumbnails/14.jpg)
What Do I Need to Know?‣ Basic object-oriented PHP to use existing entities ‣ Drupal 8’s plugin system to create new entity types ‣ Annotations
![Page 15: What's New in Drupal 8: Entity Field API](https://reader034.fdocuments.net/reader034/viewer/2022042611/58797c661a28ab6c358b4a0f/html5/thumbnails/15.jpg)
Recap‣ Unified Entity Field API – Everything is an entity ‣ Improved API for accessing field data ‣ Full CRUD support and additional management
provided by handlers ‣ Improvements to related tools made possible by
updating the underlying architecture