function context_reaction_view_mode::execute in Contextual View Modes 7.3
Execute and return the type of entity view mode that should be used.
Parameters
string $type: The type of entity we are working on.
object $entity: The entity object to be evaluated.
Return value
mixed False if no match or a string of the view mode if matched.
File
- plugins/
context_reaction.view_mode.inc, line 81
Class
Code
function execute(&$entity, $type) {
// Be safe, wrap it up.
$wrapped = entity_metadata_wrapper($type, $entity);
// Get the bundle type.
$bundle = $wrapped
->getBundle();
// Get the available active contexts
$contexts = $this
->get_contexts();
// Loop through each active context and assert the view mode settings.
foreach ($contexts as $context) {
// The configuration options for the context.
$options = $this
->fetch_from_context($context);
// If no setting found keep moving along.
if (!isset($options['entity_types'][$type][$bundle])) {
continue;
}
// If we find a match then return the view mode string.
if ($options['entity_types'][$type][$bundle] !== "none") {
return $options['entity_types'][$type][$bundle];
}
}
// Nothing matched. Return false.
return FALSE;
}