function hook_metatag_get_entity_metatags_instance_alter in Metatag 7
Allow the Metatag config instance name to be changed.
By default, Metatag module define config instance per entity bundle, making it impossible to store set of meta tags based on other criteria. Combining this hook with hook_metatag_config_instance_info_alter() it is possible to alter the logic of how instances are named based on any custom criteria.
Parameters
string $instance: The name of the instance generated by default.
object $entity: The entity object to generate the Metatag instance name for.
string $entity_type: The entity type of the entity.
string $bundle: The bundle of the entity.
1 invocation of hook_metatag_get_entity_metatags_instance_alter()
- metatag_get_entity_metatags_instance in ./
metatag.module - Build and alter metatag instance name.
File
- ./
metatag.api.php, line 110 - API documentation for the Metatag module.
Code
function hook_metatag_get_entity_metatags_instance_alter(&$instance, $entity, $entity_type, $bundle) {
if ($entity_type == 'user') {
// Split config instances based on user roles.
foreach (array_reverse(user_roles(), TRUE) as $rid => $role) {
if ($rid == DRUPAL_AUTHENTICATED_RID) {
continue;
}
if (isset($entity->roles[$rid])) {
$instance = 'user:' . $role;
break;
}
}
}
}