function rabbit_hole_execute in Rabbit Hole 7.2
Determines the action that should be executed.
This will actually execute the action, and should be used when the entity is being viewed.
Parameters
string $entity_type: The entity type that's being viewed, e.g. 'node'.
object $entity: The entity that is being viewed.
Return value
false This will only return FALSE, which means that nothing was done. If something is done, this function will redirect the user immediately.
8 calls to rabbit_hole_execute()
- rh_bean_entity_view in modules/
rh_bean/ rh_bean.module - Implements hook_entity_view().
- rh_field_collection_field_collection_item_view in modules/
rh_field_collection/ rh_field_collection.module - Implements hook_field_collection_item_view().
- rh_file_file_view in modules/
rh_file/ rh_file.module - Implements hook_file_view().
- rh_node_ctools_render_alter in modules/
rh_node/ rh_node.module - Implements hook_ctools_render_alter().
- rh_node_node_view in modules/
rh_node/ rh_node.module - Implements hook_node_view().
File
- ./
rabbit_hole.module, line 297 - Main module file for Rabbit Hole.
Code
function rabbit_hole_execute($entity_type, $entity) {
global $language;
$action = rabbit_hole_get_action($entity_type, $entity);
$context = array(
'entity_type' => $entity_type,
'entity' => $entity,
);
drupal_alter('rabbit_hole_execute', $action, $context);
switch ($action) {
case RABBIT_HOLE_ACCESS_DENIED:
// Deliver a 403, and exit.
drupal_access_denied();
drupal_exit();
case RABBIT_HOLE_PAGE_NOT_FOUND:
// Deliver a 404, and exit.
drupal_set_title(t('Page not found'));
drupal_not_found();
drupal_exit();
case RABBIT_HOLE_PAGE_REDIRECT:
// Determine the source of the redirect. This will be the entity itself,
// or the default settings from the bundle.
if (rabbit_hole_get_action_entity($entity_type, $entity) != RABBIT_HOLE_USE_DEFAULT) {
// Get the redirect path and response from the entity.
$redirect = rabbit_hole_get_redirect_entity($entity_type, $entity);
$redirect_response = rabbit_hole_get_redirect_response_entity($entity_type, $entity);
}
else {
// Get the redirect path and response from the bundle.
$bundle = rabbit_hole_entity_get_bundle($entity_type, $entity);
$redirect = rabbit_hole_get_redirect_bundle($entity_type, $bundle);
$redirect_response = rabbit_hole_get_redirect_response_bundle($entity_type, $bundle);
}
// Process the PHP code, if it has been provided.
if (rabbit_hole_contains_php($redirect)) {
// Retrieve the PHP code.
$php = preg_replace('/(.*(?=\\<\\?php)|(?<=\\?\\>).*)/uis', '', $redirect);
// Evaluate the PHP code.
$result = rabbit_hole_eval($php, $entity);
// If the code returned FALSE, we'll exit since the user shouldn't get
// redirected.
if ($result === FALSE) {
return FALSE;
}
// Replace the PHP part with the evaluation result. If the result isn't
// a string, we'll remove the PHP part altogether.
$result = is_string($result) ? $result : '';
$redirect = str_replace($php, $result, $redirect);
}
// Remove any line breaks and strip whitespaces from the beginning and the
// end of the string.
$redirect = trim(str_replace(array(
"\r",
"\n",
), '', $redirect));
// Replace any tokens with real values.
$entity_info = entity_get_info($entity_type);
$token_data = isset($entity_info['token type']) ? array(
$entity_info['token type'] => $entity,
) : array();
$redirect = token_replace($redirect, $token_data, array(
'language' => $language,
'clear' => TRUE,
));
// Parse the supplied redirect path in order to get the details.
$redirect_data = drupal_parse_url($redirect);
// Perform the redirect.
drupal_goto($redirect_data['path'], $redirect_data, $redirect_response);
default:
// There's nothing to do.
return FALSE;
}
}