You are here

function entity_translation_hierarchy_is_blocked in Language Hierarchy 7

Checks if for given language the entity is blocked.

_type

Parameters

$entity:

$langcode:

Return value

bool

3 calls to entity_translation_hierarchy_is_blocked()
entity_translation_hierarchy_node_access in modules/entity_translation_hierarchy/entity_translation_hierarchy.node.inc
Implements hook_node_access().
hreflang_hierarchy_get_links in modules/hreflang_hierarchy/hreflang_hierarchy.module
Gets hreflang links for given path.
xmlsitemap_language_hierarchy_create_link in modules/xmlsitemap_language_hierarchy/xmlsitemap_language_hierarchy.module
Create a sitemap link from a node.

File

modules/entity_translation_hierarchy/entity_translation_hierarchy.module, line 267

Code

function entity_translation_hierarchy_is_blocked($entity, $entity_type, $langcode) {
  if (!entity_translation_enabled($entity_type, $entity)) {
    return FALSE;
  }
  if ($handler = entity_translation_get_handler($entity_type, $entity, TRUE)) {

    // Get translations from the entity we're trying to view and determine what
    // are the translation candidates and figure out which candidate is going to
    // be viewed.
    if ($translations = $handler
      ->getTranslations()) {

      // If the entity doesn't have any translation data associated we consider it non-blocking.
      if (!isset($translations) || !$translations->original || empty($translations->data)) {
        return FALSE;
      }
      $view_candidate = entity_translation_hierarchy_get_candidate($entity, $entity_type, $langcode);

      // If there's no view candidate at all (No parents have translations), then mark as blocking too.
      if (!$view_candidate) {
        return TRUE;
      }
      $is_blocking = !empty($translations->data[$view_candidate]['blocking']);

      // Block access to this entity if this translation is blocking.
      if ($is_blocking && (!user_access('translate any entity') && !user_access("translate {$entity_type} entities"))) {
        return TRUE;
      }
    }
  }
  return FALSE;
}