You are here

function metatag_entity_type_is_suitable in Metatag 7

Identify whether an entity type is technically capable of having meta tags.

In order to be capable of having meta tags, an entity type must have view modes, must be fieldable, and may not be a configuration entity.

Parameters

string $entity_type: The entity type.

array $entity_info: Entity information.

Return value

bool Return TRUE if suitable.

2 calls to metatag_entity_type_is_suitable()
metatag_admin_settings_form in ./metatag.admin.inc
Misc settings page.
metatag_entity_supports_metatags in ./metatag.module
Check whether the requested entity type (and bundle) support metatag.

File

./metatag.module, line 2907
Primary hook implementations for Metatag.

Code

function metatag_entity_type_is_suitable($entity_type, array $entity_info = array()) {
  $suitable = TRUE;

  // If the entity info was not passed along, load it.
  if (empty($entity_info)) {
    $entity_info = entity_get_info($entity_type);
  }

  // Configuration entities may not have meta tags.
  if (isset($entity_info['configuration']) && $entity_info['configuration'] == TRUE) {
    $suitable = FALSE;
  }
  elseif (empty($entity_info['bundles'])) {
    $suitable = FALSE;
  }
  elseif (empty($entity_info['fieldable'])) {
    $suitable = FALSE;
  }
  else {

    // Ignore some view modes that are automatically added by certain modules.
    unset($entity_info['view modes']['ical']);
    unset($entity_info['view modes']['diff_standard']);
    unset($entity_info['view modes']['token']);

    // There must be view modes.
    if (empty($entity_info['view modes'])) {
      $suitable = FALSE;
    }
    else {

      // Specifically disable some entity types.
      $excluded = array(
        // Comment module.
        'comment',
        // Field Collection module.
        'field_collection_item',
        // Paragraphs module.
        'paragraphs_item',
      );
      if (in_array($entity_type, $excluded)) {
        $suitable = FALSE;
      }
    }
  }

  // Trigger hook_metatag_entity_type_is_supported_alter() to allow other
  // modules to either enable or disable certain entity types.
  drupal_alter('metatag_entity_type_is_supported', $suitable, $entity_type, $entity_info);
  return $suitable;
}