function atom_reference_field_formatter_view in Scald: Media Management made easy 7
Implements hook_field_formatter_view.
File
- modules/
fields/ atom_reference/ atom_reference.module, line 224 - Defines a new field type, allowing to directly reference Scald Atoms from a node.
Code
function atom_reference_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
$render_context = $display['type'];
$contexts = scald_contexts();
$element = array();
$uri = false;
// Check if the formatter involves a link.
if ($display['settings']['link']) {
$uri = entity_uri($entity_type, $entity);
}
if (!empty($contexts[$render_context])) {
foreach ($items as $delta => $item) {
$options = array();
if (!empty($item['options'])) {
$options += unserialize($item['options']);
}
$context = $render_context;
if (isset($display['settings']['override']) && $display['settings']['override'] && !empty($options['context']) && $options['context'] !== 'use_the_default') {
$context = $options['context'];
}
$sid = $item['sid'];
if ($uri) {
$options['link'] = $uri['path'];
}
$element[$delta] = array(
'#markup' => scald_render($sid, $context, drupal_json_encode($options)),
);
}
}
return $element;
}