You are here

function power_menu_get_fields_entity_by_mlid in Power Menu 7.2

Gets the Power Menu Fields entity for given Menu Link ID

Parameters

$mlid: The Menu Link ID to search for the fields entity.

Return value

The entity or NULL is no entity found for the given Menu Link ID

File

./power_menu.module, line 931

Code

function power_menu_get_fields_entity_by_mlid($mlid) {
  $cache_key = 'fields:mlid:' . $mlid;
  $entity = cache_get($cache_key, 'cache_power_menu');
  $entity = $entity ? $entity->data : NULL;

  // Is the entity not cached, load it
  if (!$entity) {

    // Get the menu link from given mlid
    $id = power_menu_get_fields_entity_id_by_mlid($mlid);
    if ($id) {
      $entity = entity_load('power_menu_fields', array(
        $id,
      ));

      // Return only the entity and not an array
      $entity = $entity ? array_pop($entity) : NULL;
    }
    cache_set($cache_key, $entity, 'cache_power_menu');
  }
  return $entity;
}