Programming Drupal 7 Entities

Programming Drupal 7 Entities
eBook: $18.99
Formats: PDF, PacktLib, ePub and Mobi formats
save 15%!
Print + free eBook + free PacktLib access to the book: $53.98    Print cover: $34.99
save 35%!
Free Shipping!
UK, US, Europe and selected countries in Asia.
Also available on:
Table of Contents
Sample Chapters
  • 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

Book Details

Language : English
Paperback : 134 pages [ 235mm x 191mm ]
Release Date : June 2013
ISBN : 1782166521
ISBN 13 : 9781782166528
Author(s) : Sammy Spets
Topics and Technologies : All Books, CMS and eCommerce, Open Source

Table of Contents

Chapter 1: Understanding Entities
Chapter 2: Developing with Entity Metadata Wrappers
Chapter 3: Developing with Non-fieldable Entities
Chapter 4: Developing with Fieldable Entities
Chapter 5: Developing with Fields
Chapter 6: Developing with Field Collections
Chapter 7: Expose Local Entities
Chapter 8: Expose Remote Entities
  • Chapter 1: Understanding Entities
    • Introducing entities
    • Entity and solution modules
    • Introducing entity types, bundles, and fields
      • Types
      • Bundles
      • Fields
      • Drupal core entity structure
    • Powerful entity use cases
      • User profiles
      • Internationalization
      • Commerce products
    • Our use case
    • Summary
    • Chapter 2: Developing with Entity Metadata Wrappers
      • Introducing entity metadata wrappers
      • Creating an entity metadata wrapper object
      • Standard entity properties
      • Entity introspection
      • Using an entity metadata wrapper
        • Create
          • Drush commands
          • Code snippet
        • Retrieve
          • Drush commands
          • Code snippet
        • Update
          • Drush commands
          • Code snippet
        • Delete
          • Drush commands
          • Code snippet
      • Safely using text property values
      • Self-imposed limitation of entity programming
      • References
      • A note about EntityFieldQuery
      • Summary
          • Chapter 5: Developing with Fields
            • Field types
            • Single-value and multi-value fields
            • Structure fields
              • Field type-specific code
                • File and image fields
                • Link fields
                • Datetime fields
                • Putting it all together
            • Converting the recipe content type to use fields
              • Creating fields
              • Exporting fields to a feature
              • Copying the code to the recipe module
              • Tweaking recipe.module and
              • Upgrading recipe module
            • Summary
            • Chapter 6: Developing with Field Collections
              • Before Drupal 7
              • Creating a field collection field
              • Field collection entities
              • Adding a field collection to a node
              • Attaching a field collection to a content type
                • Exporting field collection and fields
                • Copying the code to the recipe module
                • Tweaking recipe.module
                • Updating code is unnecessary
              • Summary
              • Chapter 7: Expose Local Entities
                • Motivation for exposing entities
                • Fast track your data exposure
                • Allow fields on your entity
                • Give it multiple bundles
                • Administration interface and exportability
                  • Storing bundle information
                  • Exposing bundle information and handling access rights
                  • Adding the support code
                • Summary
                • Chapter 8: Expose Remote Entities
                  • Introducing the Remote Entity API
                  • Requirements for exposing remote entities
                  • Implementing remote entity exposure
                    • Database schema
                    • Connection code
                    • Remote query code
                    • Entity exposure code
                    • Entity metadata API integration
                    • Import and administration code
                  • Running
                  • Adding write support
                  • Customization for your use case
                  • Summary

                  Sammy Spets

                  Since 2004, Sammy Spets has been finding pleasure in his life making Drupal do wild things. During that time, Sammy volunteered to be a core maintainer for Drupal 6 and a maintainer of the ecommerce module, which was the commerce module of choice way back when. For the ecommerce module, Sammy made design changes to the payment system, built a few modules to support payment gateways, and added PostgreSQL support, among other things. In 2008, IDG Australia contracted Sammy to design and lead the development of a hybrid Drupal/legacy platform. The platform allowed IDG developers to gradually migrate their websites and web applications over to Drupal 6, which was still in beta. In addition to the platform, Sammy was tasked with creating a module suite for the IDG staff to create surveys and reports on them. This module suite was built prior to webform, and leveraged the power of the Drupal 6 Form API in all its glory. Sammy also trained IDG developers to develop modules and themes in Drupal 6. Early in 2009, a short contract with Demonz Media in Sydney, Australia brought about some patches to Ubercart, which Demonz gladly contributed back to the community. Following that, Sammy travelled to Louisville, Kentucky, USA where he contributed code to improve the developer experience for developers extending Ubercart by using its API. Ryan Szrama introduced Sammy to Chick-fil-A and Lyle Mantooth introduced Sammy to Korean food and some amazing fried chicken. In 2011, Sammy joined the Magicspark team, building Drupal sites and maintaining servers. During this time, Sammy built a services platform to feed webform data to Marketo and LoopFuse from client Drupal sites via Magicspark's servers. In addition to this, Sammy redeveloped the UI on the Where to Buy page of the Redwood Systems website using OpenLayers mapping. Aside from the geeky stuff, Sammy loves to cook, fine-tune recipes, play pool, carve turns on a snowboard, hit the gym, ride motorcycles, dine fine, and drink champagne. Programming Drupal 7 Entities, Packt Publishing, is the first book Sammy has authored. Sammy was the technical reviewer for Migrating to Drupal 7, Packt Publishing. Sammy can be contacted by e-mail at
                  Sorry, we don't have any reviews for this title yet.

                  Code Downloads

                  Download the code and support files for this book.

                  Submit Errata

                  Please let us know if you have found any errors not listed on this list by completing our errata submission form. Our editors will check them and add them to this list. Thank you.


                  - 1 submitted: last submission 14 Feb 2014

                  Errata Type : Technical   Page: 19


                  On page 19, in the first line of code under the Code snippet section under the Retrieve section needs a part to be highlighted. The correction is shown in the following line of code:

                  $header = ' Entity (' . $wrapper->type();

                  Sample chapters

                  You can view our sample chapters and prefaces of this title on PacktLib or download sample chapters in PDF format.

                  Frequently bought together

                  Programming Drupal 7 Entities +    SilverStripe 2.4 Module Extension, Themes, and Widgets: Beginner's Guide =
                  50% Off
                  the second eBook
                  Price for both: $32.45

                  Buy both these recommended eBooks together and get 50% off the cheapest eBook.

                  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

                  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.


                  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 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.

                  Code Download and Errata
                  Packt Anytime, Anywhere
                  Register Books
                  Print Upgrades
                  eBook Downloads
                  Video Support
                  Contact Us
                  Awards Voting Nominations Previous Winners
                  Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
                  Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software