function metatag_entity_supports_metatags in Metatag 7
Check whether the requested entity type (and bundle) support metatag.
By default the entities are disabled, only certain entities will have been enabled during installation. If an entity type is enabled it is assumed that the entity bundles will also be enabled by default.
See also
metatag_entity_type_is_suitable()
19 calls to metatag_entity_supports_metatags()
- MetatagBulkRevertTest::testBulkRevertPageLoads in tests/
MetatagBulkRevertTest.test - Test the Bulk Revert functionality works.
- MetatagCoreUnitTest::assertMetatagEntitySupportsMetatags in tests/
MetatagCoreUnitTest.test - Confirm an entity supports meta tags.
- metatag_admin_settings_form in ./
metatag.admin.inc - Misc settings page.
- metatag_bulk_revert_form in ./
metatag.admin.inc - Form constructor to revert nodes to their default metatags.
- metatag_entity_insert in ./
metatag.module - Implements hook_entity_insert().
7 string references to 'metatag_entity_supports_metatags'
- metatag_config_cache_clear in ./
metatag.module - Clear the metatag configuration cache.
- metatag_entity_type_disable in ./
metatag.module - Disable support for a specific entity type.
- metatag_entity_type_enable in ./
metatag.module - Enable support for a specific entity type if setting does not exist.
- metatag_update_7036 in ./
metatag.install - Update variables to indicate which entities should be supported.
- metatag_update_delete_config in ./
metatag.install - Remove a specific meta tag from all configs.
File
- ./
metatag.module, line 1786 - Primary hook implementations for Metatag.
Code
function metatag_entity_supports_metatags($entity_type = NULL, $bundle = NULL) {
$entity_types =& drupal_static(__FUNCTION__);
// Identify which entities & bundles are supported the first time the
// function is called.
if (!isset($entity_types)) {
foreach (entity_get_info() as $entity_name => $entity_info) {
// Verify that this entity type is suitable.
$entity_types[$entity_name] = metatag_entity_type_is_suitable($entity_name, $entity_info);
// The entity type technically supports entities.
if (!empty($entity_types[$entity_name])) {
// Entiy types are enabled by default.
// Allow entities to be disabled by assigning a variable
// 'metatag_enable_{$entity_type}' the value FALSE, e.g.:
// @code
// // Disable metatags for file_entity.
// $conf['metatag_enable_file'] = FALSE;
// @endcode
// @see Settings page.
if (variable_get('metatag_enable_' . $entity_name, FALSE) == FALSE) {
$entity_types[$entity_name] = FALSE;
}
else {
$entity_types[$entity_name] = array();
foreach ($entity_info['bundles'] as $bundle_name => $bundle_info) {
// If only one bundle exists, take configuration for entity, to
// reflect options as they are available in the UI.
if (count($entity_info['bundles']) === 1) {
$entity_types[$entity_name][$bundle_name] = variable_get('metatag_enable_' . $entity_name, FALSE) == TRUE;
continue;
}
// Allow bundles to be disabled by assigning a variable
// 'metatag_enable_{$entity_type}__{$bundle}' the value FALSE, e.g.:
// @code
// // Disable metatags for carousel nodes.
// $conf['metatag_enable_node__carousel'] = FALSE;
// @endcode
// @see Settings page.
if (variable_get('metatag_enable_' . $entity_name . '__' . $bundle_name, TRUE) == FALSE) {
$entity_types[$entity_name][$bundle_name] = FALSE;
}
else {
$entity_types[$entity_name][$bundle_name] = TRUE;
}
}
}
}
}
}
// It was requested to check a specific entity.
if (isset($entity_type)) {
// It was also requested to check a specific bundle for this entity.
if (isset($bundle)) {
$supported = !empty($entity_types[$entity_type][$bundle]);
}
else {
$supported = !empty($entity_types[$entity_type]);
}
return $supported;
}
// If nothing specific was requested, return the complete list of supported
// entities & bundles.
return $entity_types;
}