function context_field_field_formatter_view in Context Field 7
Implements hook_field_formatter_view().
For the formatter we are setting the context saved in the field and returning an empty array
File
- ./
context_field.module, line 500 - Context Field
Code
function context_field_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
$path = drupal_get_path("module", 'context_field');
drupal_add_css($path . '/context_field.css');
$entity_info = entity_get_info($entity_type);
$id_field = $entity_info['entity keys']['id'];
$id = $entity->{$id_field};
if (isset($entity->{$instance['field_name']}[$langcode]) && ($plugin = context_get_plugin('condition', 'context_field'))) {
foreach ($entity->{$instance['field_name']}[$langcode] as $field_value) {
if ($instance['settings']['use_default']) {
$plugin
->execute($instance['settings']['default_context']);
}
else {
$plugin
->execute($field_value['context']);
}
// If we are using the context_ui add which blocks should be allowed
// to Drupal.settings
if (context_isset('context_ui', 'context_ui_editor_present')) {
// set a value for which blocks should be allowed in the inline editor
// we are setting this in js
// TODO: use js to limit these values
$allowed_blocks =& drupal_static(__FUNCTION__);
$allowed_blocks[$field_value['context']] = $instance['settings']['allowed_blocks'];
drupal_add_js(array(
"context_field_allowed_blocks" => $allowed_blocks,
), 'setting');
}
}
}
return array();
}