function safeword_context_condition::execute in Safeword 8
Same name and namespace in other branches
- 7 safeword_context/safeword_context_condition.inc \safeword_context_condition::execute()
File
- safeword_context/
safeword_context_condition.inc, line 54
Class
Code
function execute($entity_type, $entity, $op = 'view') {
// Only 'view' for now.
if ($op != 'view') {
return;
}
list(, , $bundle) = entity_extract_ids($entity_type, $entity);
$fields_map = field_info_field_map();
foreach ($fields_map as $field_name => $field_usage) {
if ($field_usage['type'] == 'safeword' || $field_usage['type'] == 'safeword_title') {
if (isset($field_usage['bundles'][$entity_type]) && in_array($bundle, $field_usage['bundles'][$entity_type])) {
$items = field_get_items($entity_type, $entity, $field_name);
if ($items) {
$machine_name = $items[0]['machine'];
$contexts = $this
->get_contexts($machine_name);
foreach ($contexts as $name => $context) {
$options = $this
->fetch_from_context($context, 'options');
if (empty($options['entity_types']) || !empty($options['entity_types'][$entity_type])) {
$this
->condition_met($context, $machine_name);
}
}
}
break;
}
}
}
}