You are here

function entity_menu_links_linked_entity in Entity menu links 7

Returns an array with info about the entity that a menu_link links to based on it's link_path.

Parameters

object $menu_link: The menu_link entity

bool $universalised: Whether the menu_link entity is universalised

Return value

array | FALSE Eg. array('type' => 'node', 'id' => 123) OR array('type' => 'node', 'uuid' => <uuid> ) if $universalised = TRUE OR FALSE if the menu_link doesn't link to an entity.

3 calls to entity_menu_links_linked_entity()
entity_menu_links_entity_dependencies in ./entity_menu_links.module
Implements hook_entity_dependencies().
entity_menu_links_entity_uuid_load in ./entity_menu_links.module
Implements hook_entity_uuid_load().
entity_menu_links_entity_uuid_presave in ./entity_menu_links.module
Implements hook_entity_uuid_presave().

File

./entity_menu_links.module, line 218
Entity menu link module

Code

function entity_menu_links_linked_entity($menu_link, $universalised = FALSE) {
  static $linked_entities = array();
  $cid = ($universalised ? 'uuid' : 'id') . $menu_link->mlid;
  if (isset($linked_entities[$cid])) {
    return $linked_entities[$cid];
  }
  $linked_entity = FALSE;
  drupal_alter('entity_menu_links_linked_entity', $linked_entity, $menu_link, $universalised);
  if ($universalised) {
    $regexp = '#([^/]+)/(' . UUID_PATTERN . ')$#';
  }
  else {
    $regexp = '#([^/]+)/(\\d+)#';
  }
  if (empty($linked_entity) && preg_match($regexp, $menu_link->link_path, $matches)) {
    $type = $matches[1];
    $id = $matches[2];
    $info = entity_get_info($type);
    if (!empty($info['uuid'])) {
      $linked_entity = array(
        'type' => $type,
      );
      if ($universalised) {
        $linked_entity['uuid'] = $id;
      }
      else {
        $linked_entity['id'] = $id;
      }
    }
  }
  return $linked_entities[$cid] = $linked_entity;
}