You are here

function fc_get_page_entity in Field Complete 7

3 calls to fc_get_page_entity()
_fc_incomplete_block_view in fc_incomplete/fc_incomplete.blocks.inc
Implements hook_block_view().
_fc_progress_block_view in fc_progress/fc_progress.blocks.inc
Implements hook_block_view().
_fc_progress_block_view_profile2 in fc_progress/fc_progress.blocks.inc
Figure out the profile2 entity for this page (if there is one)

File

./fc.module, line 379
Field Complete - Provides field-based completeness for any entity.

Code

function fc_get_page_entity($entity_type) {
  $entity = NULL;
  $entity_info = entity_get_info($entity_type);
  if ($entity_type == 'profile2') {

    // Special handling for profile2 (again)
    $router_item = menu_get_item();
    foreach ($router_item['page_arguments'] as $arg) {
      if ($arg instanceof Profile) {
        $entity = $arg;
        break;
      }
    }
  }
  else {

    // Figure out the URL structure, build a dummy entity
    // then fetch its URL.
    $dummy = (object) array(
      $entity_info['entity keys']['id'] => 0,
    );
    $uri = $entity_info['uri callback']($dummy);
    $path = explode('/', $uri['path']);
    $pos = 0;
    while (($el = array_shift($path)) && ++$pos) {
      if (is_numeric($el)) {
        break;
      }
    }

    // Get the actual entity for this page
    $entity = menu_get_object($entity_type, $pos);
  }
  return $entity;
}