Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Attempt to fetch the entity that is being viewed via a backtrace to the
- // field_attach_view($entity_type, $entity) function and parameters §if found.
- $backtrace = debug_backtrace();
- foreach ($backtrace as $caller) {
- if ($caller['function'] == 'field_attach_view') {
- $entity_type = $caller['args'][0];
- $entity = $caller['args'][2];
- // do stuff with entity
- break;
- }
- }
- function($entity, $entity_type)
- function MODULE_entity_load($entities, $entity_type) {
- foreach ($entities as $entity) {
- $entity->entity_type = $entity_type;
- }
- }
- function entity_by_path($path) {
- $router_item = menu_get_item($path);
- $ent_sug_array = array();
- foreach ($router_item['map'] as $key => $value) {
- if(is_object($value) && isset($value->type)) {
- $ent_sug_array[$key] = $value;
- }
- }
- $ent_sug = false;
- if(count($ent_sug_array) > 1) {
- $lf_sug = false;
- if(isset($router_item['load_functions'])) {
- if(count($router_item['load_functions']) == 1) {
- reset($router_item['load_functions']);
- $lf_sug = key($router_item['load_functions']);
- }
- }
- if($lf_sug !== false) {
- $ent_sug = is_object($router_item['map'][$lg_sug] && isset($router_item['map'][$lg_sug]->type)) ? $router_item['map'][$lg_sug] : $ent_sug;
- }
- } elseif(count($ent_sug_array) == 1) {
- $ent_sug = reset($ent_sug_array);
- }
- if(!empty($ent_sug)) {
- $bundle = $ent_sug->type;
- $ent_type = method_exists($ent_sug, 'entityType') ? $ent_sug->entityType() : false; //eck case
- if(empty($ent_type)) {
- $aclass = get_class($ent_sug);
- if($aclass == 'stdClass') {
- //node, user, core entity case
- if(isset($router_item['load_functions'])) {
- $lf = reset($router_item['load_functions']);
- $ei = entity_get_info();
- foreach ($ei as $key => $value) {
- if(empty('load hook'))
- continue;
- if($lf == $value['load hook']) {
- $ent_type = $key;
- break;
- }
- }
- }
- }else{
- //custom entity case
- $ent_type = $aclass;
- }
- }
- return array('entity'=>$ent_sug, 'type'=>$ent_type, 'bundle'=>$bundle);
- }
- return false;
- }
- $item = menu_get_item($_GET['internal_path']);
- if (empty($item['access']) || empty($item['page_arguments'][0]) || empty($item['load_functions'])) {
- return FALSE;
- }
- $entity = $item['page_arguments'][0];
- // Get entity-type.
- $load_function = reset($item['load_functions']);
- $entity_types = entity_get_info();
- $entity_type = '';
- foreach ($entity_types as $type => $type_definition) {
- if ($load_function == $type_definition['load hook']) {
- // When the load_function from menu_get_item matches "hook load" of the
- // entity type definition, then the entity_type was found.
- $entity_type = $type;
- break;
- }
- }
- if (!$entity_type) {
- return FALSE;
- }
Add Comment
Please, Sign In to add comment