Community Documentation

Additional hooks for exportable entities

Last updated April 26, 2012. Created by fago on December 16, 2010.
Edited by alexweber, drunken monkey. Log in to edit this page.

Values to replace:

{ENTITY_ID} The machine name of your entity type, e.g. "taxonomy_term".
{ENTITY} The term for a single entity.
{ENTITIES} The term for several entities.
{$ENTITY} A variable for a single entity.
{$ENTITIES} A variable for an array of entities.

/**
* Define default {ENTITY} configurations.
*
* @return
*   An array of default {ENTITIES}, keyed by machine names.
*
* @see hook_default_{ENTITY_ID}_alter()
*/
function hook_default_{ENTITY_ID}() {
  $defaults['main'] = entity_create('{ENTITY_ID}', array(
    // …
  ));
  return $defaults;
}

/**
* Alter default {ENTITY} configurations.
*
* @param array $defaults
*   An array of default {ENTITIES}, keyed by machine names.
*
* @see hook_default_{ENTITY_ID}()
*/
function hook_default_{ENTITY_ID}_alter(array &$defaults) {
  $defaults['main']->name = 'custom name';
}

/**
* Act after rebuilding default {ENTITIES}.
*
* This hook is invoked by the entity module after default {ENTITIES}
* have been rebuilt; i.e. defaults have been saved to the database.
*
* @param {$ENTITIES}
*   The array of default {ENTITIES} which have been inserted or
*   updated, keyed by name.
* @param $originals
*   An array of original {ENTITIES} keyed by name; i.e. the {ENTITIES}
*   before the current defaults have been applied. For inserted
*   {ENTITIES} no original is available.
*
* @see hook_default_{ENTITY_ID}()
* @see entity_defaults_rebuild()
*/
function hook_{ENTITY_ID}_defaults_rebuild({$ENTITIES}, $originals) {
}

Page status

No known problems

Log in to edit this page

About this page

Drupal version
Drupal 7.x
Audience
Programmers
Drupal’s online documentation is © 2000-2013 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.
nobody click here