Programming Drupal 7 Entities

Programming Drupal 7 Entities

Sammy Spets

Language: English

Pages: 134

ISBN: 1782166521

Format: PDF / Kindle (mobi) / ePub


Expose local or remote data as Drupal 7 entities and build custom solutions

Overview

  • Understand and develop using the entity paradigm and entity metadata wrappers
  • Create, retrieve, update, and delete (CRUD) operations on all entities
  • Programmatically attach fields to entities and manipulate their data
  • Expose remote data in a non-fieldable or fieldable entity with support for the import and export of bundle configurations
  • Thorough coverage of common core and contributed entity types along with custom data exposure

In Detail

Writing code for manipulating Drupal data has never been easier! Learn to dice and serve your data as you slowly peel back the layers of the Drupal entity onion. Next, expose your legacy local and remote data to take full advantage of Drupal's vast solution space.

Programming Drupal 7 Entities is a practical, hands-on guide that provides you with a thorough knowledge of Drupal's entity paradigm and a number of clear step-by-step exercises, which will help you take advantage of the real power that is available when developing using entities.

This book looks at the Drupal 7 entity paradigm, and breaks down the mystery and confusion that developers face when building custom solutions using entities. It will take you through a number of clear, practical recipes that will help you to take full advantage of Drupal entities in your web solutions without much coding.

You will also learn how to expose local and remote data to give your legacy data new life as fully-fledged Drupal entities that can be used by other modules such as views, rules, and so on. In addition to this, you'll learn to create, retrieve, update, and delete (CRUD) entities, their properties and fields, along with some programmatic wizardry to manipulate complex entities such as field collections. If you want to develop quickly and easily using Drupal entities, then this is the book for you.

You will learn everything you need to know to develop code and expose data using entities in Programming Drupal 7 Entities.

What you will learn from this book

  • Manipulate and utilize comment, file, field collection, node, term, user, and vocabulary entities
  • Attach, manipulate, and utilize date, file, image, link, number, text, and term reference fields
  • Write type-agnostic code dealing with more types of Drupal data than ever before
  • Upgrade a legacy Drupal node module to expose and utilize entities
  • Expose your legacy database tables as fully-fledged Drupal entities
  • Batch import remote data and expose them as entities
  • Glean good coding practices for dealing with entities

Approach

The book follows a standard tutorial-based approach to create, retrieve, update, and delete Drupal 7 entities, their properties and fields.

Who this book is written for

Programming Drupal 7 Entities is perfect for intermediate or advanced developers new to Drupal entity development who are looking to get a good grounding in how to code using the new paradigm. It’s assumed that you will have some experience in PHP development already, and being vaguely familiar with Drupal, GIT, and Drush will also help.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Drupal Entities!\n"; $file = file_save_data($content, $uri, FILE_EXISTS_REPLACE); $wrapper = entity_metadata_wrapper('file', $file); As you can see, we get a wrapper object in less lines by using the File API. Seeing that updating status is impossible using wrappers, we must directly use the entity. Let's pretend that we want to flag the file for removal on a later cron run. This is done by setting the file entity's status to FILE_STATUS_TEMPORARY. The code would be as follows: $wrapper =

type . Unfortunately, these outputs are accessed inconsistently throughout the different field types. For example, one field type returns raw output for a call to value() whereas a different field type outputs sanitized output. Wipe the sweat off your brow and take a deep breath. There's a way around it, and those of you who guess it right get a candy bar. We can get what we want by calling value() and giving it an option to specify the processing type. For each processing type the code is as

follows: raw: $wrapper->body->summary->value(array('decode' => TRUE)); sanitized: $wrapper->body->summary->value(array('sanitize' => TRUE)); So, that was easy right? Indeed it was. That's all of the tricks necessary if your code deals with a known entity type or field type. If you need to do anything generic, write code targeting the field type, as the field type must declare a fixed set of property names and types. Don't forget though...programming at the entity-level should have nothing

IngredientTypeUIController: This enables overriding of the EntityDefaultUIController class in order to set the menu item description Adding the support code To complete the overhaul, we add some class declarations and functions to recipe.module and recipe.admin.inc. First, add the following code to recipe.admin.inc: /** * Generates the recipe_ingredient_type editing form. */ function recipe_ingredient_type_form($form, &$form_state, $recipe_ingredient_type, $op = 'edit') { if ($op ==

learning about entities in general by using hypothetical entities. It is now time to play with some of the entity structures exposed by Drupal core. In this chapter we will cover the following: What non-fieldable entities are File entities Vocabulary entities Programmatically creating a file and a vocabulary Programmatically modifying a file and a vocabulary What are non-fieldable entities? So far in this book, we have only brushed on non-fieldable entities, so a little more detail

Download sample

Download