function pathauto_entity_entity_insert in Pathauto Entity 7
Implements hook_entity_insert().
1 call to pathauto_entity_entity_insert()
- pathauto_entity_entity_update in ./
pathauto_entity.module - Implements hook_entity_update().
File
- ./
pathauto_entity.module, line 258 - Implements custom entity type support for Pathauto module.
Code
function pathauto_entity_entity_insert($entity, $entity_type) {
// If using an Alternative or custom URL alias
if (isset($entity->path) && isset($entity->path['pathauto']) && $entity->path['pathauto'] == '0') {
$path = $entity->path;
$path['alias'] = trim($path['alias']);
// Only save a non-empty alias.
if (!empty($path['alias'])) {
// Ensure fields for programmatic executions.
$langcode = entity_language($entity_type, $entity);
$default_uri = entity_uri($entity_type, $entity);
$path['source'] = $default_uri['path'];
$path['language'] = isset($langcode) ? $langcode : LANGUAGE_NONE;
path_save($path);
}
}
else {
// Use Pathauto generaed path alias
pathauto_entity_update_alias($entity_type, $entity, 'insert');
}
}