You are here

function entity_menu_links_entity_dependencies in Entity menu links 7

Implements hook_entity_dependencies().

File

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

Code

function entity_menu_links_entity_dependencies($entity, $entity_type) {
  if ($entity_type == 'menu_link') {
    $dependencies = array();

    // Eg. array('p1', 'p2', ... 'p9')
    $parent_property_names = entity_menu_links_parent_properties();
    $plids = array();
    foreach ($parent_property_names as $pn) {
      $plids[] = (int) $entity->{$pn};
    }
    $plids = implode(',', $plids);

    // Don't add system menu items as dependencies, since they are not
    // considered entities by entity_menu_links.
    $menu_links = db_query("\n      SELECT mlid FROM {menu_links}\n      WHERE mlid IN ({$plids})\n      AND module = :module", array(
      ':module' => 'menu',
    ))
      ->fetchAllAssoc('mlid');
    foreach ($menu_links as $menu_link) {
      $dependencies[] = array(
        'type' => $entity_type,
        'id' => $menu_link->mlid,
      );
    }

    // Add the entity this menu_link links to, if one exists (eg. a node).
    $linked_entity = entity_menu_links_linked_entity($entity);
    if (!empty($linked_entity)) {
      $dependencies[] = $linked_entity;
    }
    return $dependencies;
  }
}