You are here

function yoast_seo_entity_supports_yoast_seo in Real-time SEO for Drupal 7

Check whether the requested entity type (and bundle) support Yoast SEO.

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_supports_metatags()

6 calls to yoast_seo_entity_supports_yoast_seo()
yoast_seo_entity_insert in ./yoast_seo.module
Implements hook_entity_insert().
yoast_seo_entity_load in ./yoast_seo.module
Implements hook_entity_load().
yoast_seo_entity_update in ./yoast_seo.module
Implements hook_entity_update().
yoast_seo_field_attach_form in ./yoast_seo.module
Implements hook_field_attach_form().
yoast_seo_form_node_admin_content_alter in ./yoast_seo.module
Implements hook_form_FORM_ID_alter().

... See full list

2 string references to 'yoast_seo_entity_supports_yoast_seo'
yoast_seo_entity_type_disable in ./yoast_seo.module
Disable support for a specific entity type.
yoast_seo_entity_type_enable in ./yoast_seo.module
Enable support for a specific entity type.

File

./yoast_seo.module, line 890
Primary hook implementations for Yoast SEO for Drupal module.

Code

function yoast_seo_entity_supports_yoast_seo($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) {

      // The entity type technically supports entities.
      // @todo, make this more generic when we are supporting more entities.
      if ($entity_name == 'node') {

        // Entity types are enabled by default.
        // Allow entities to be disabled by assigning a variable
        // 'metatag_enable_{$entity_type}' the value FALSE, e.g.:
        //
        // // Disable metatags for file_entity.
        // $conf['metatag_enable_file'] = FALSE;
        // .
        // @see Settings page.
        if (variable_get('yoast_seo_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) {

            // Allow bundles to be disabled by assigning a variable
            // 'yoast_seo_enable_{$entity_type}__{$bundle}' the value FALSE,
            // e.g.:
            if (variable_get('yoast_seo_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;
}