Additional hooks for exportable entities

Last updated on
14 October 2016

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) {
}