You are here

function _datalayer_menu_get_any_object in dataLayer 7

Same name and namespace in other branches
  1. 8 datalayer.module \_datalayer_menu_get_any_object()

Agnosticly get the current menu object. Passed type will be set for you.

Parameters

string $return_type: Pass in a type variable by reference for later use.

Return value

object Entity object of current menu callback page.

5 calls to _datalayer_menu_get_any_object()
DataLayerUnitTests::testDataLayerMenuGetAnyObjectReturnsFalseWithIncorrectArgPosition in tests/datalayer.unit.test
Test DataLayer Menu Get Any Object.
DataLayerUnitTests::testDataLayerMenuGetAnyObjectReturnsFalseWithoutLoadFunctionMatch in tests/datalayer.unit.test
Test DataLayer Menu Get Any Object.
DataLayerUnitTests::testDataLayerMenuGetAnyObjectReturnsFalseWithoutLoadFunctions in tests/datalayer.unit.test
Test DataLayer Menu Get Any Object.
DataLayerUnitTests::testDataLayerMenuGetAnyObjectReturnsObject in tests/datalayer.unit.test
Test DataLayer Menu Get Any Object Returns Object.
datalayer_get_page_data in ./datalayer.module
Return all the page meta data.

File

./datalayer.module, line 380
Client-side data space.

Code

function _datalayer_menu_get_any_object(&$return_type) {

  // Figure out how this entity is loaded.
  $type = FALSE;
  $item = menu_get_item();

  // Non-entities may not have load functions.
  if (is_array($item['load_functions'])) {
    $vals = array_values($item['load_functions']);
    $load_function = $vals[0];
    $arg_position = array_search($load_function, $item['load_functions']);

    // Compare to entity types.
    $entity_info = entity_get_info();
    foreach ($entity_info as $i => $e) {
      if ($e['load hook'] == $load_function) {
        $type = $i;
      }
    }
  }

  // Many happy returns.
  if ($type && ($obj = menu_get_object($type, $arg_position))) {
    if (is_object($obj)) {
      $return_type = $type;
      return $obj;
    }
    else {
      return FALSE;
    }
  }
  else {
    return FALSE;
  }
}