Additional hooks for exportable entities
Last updated on
14 October 2016
Drupal 7 will no longer be supported after January 5, 2025. Learn more and find resources for Drupal 7 sites
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) {
}
Help improve this page
Page status: No known problems
You can:
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion
Still on Drupal 7? Security support for Drupal 7 ended on 5 January 2025. Please visit our Drupal 7 End of Life resources page to review all of your options.