public function context_condition_entity_field::execute in Context entity field 7
Execute.
File
- plugins/
context_condition_entity_field.inc, line 96 - Implement context condiction class for entity field value.
Class
- context_condition_entity_field
- Expose entity field as a context condition.
Code
public function execute($entity_type, $entity) {
if ($this
->condition_used()) {
foreach ($this
->get_contexts() as $context) {
$settings = $this
->fetch_from_context($context, 'values');
if (in_array($entity_type, array_filter(unserialize($settings['entity_type'])))) {
$items = field_get_items($entity_type, $entity, $settings['field_name']);
// Field do not exist.
if ($items === FALSE && !isset($entity->{$settings['field_name']})) {
continue;
}
// Field value is empty.
if ($settings['field_status'] == 'empty' && $items === FALSE) {
$this
->condition_met($context);
}
// Field value is not empty.
if ($settings['field_status'] == 'all' && $items !== FALSE) {
$this
->condition_met($context);
}
// Field value match.
if ($settings['field_status'] == 'match' && $items) {
// Enable control on all field values.
$values = $this
->get_field_multiple_value($settings['field_name'], $items);
// Control value in available values.
if (in_array($settings['field_value'], $values)) {
$this
->condition_met($context);
}
}
}
}
}
}