Commit 9bdab677 authored by jurgenhaas's avatar jurgenhaas

#2367243: Implement support for entityreference field types

parent d53ac521
......@@ -12,7 +12,7 @@ function colorbox_field_formatter_field_formatter_info() {
return array(
'colorbox_field_formatter_linked' => array(
'label' => t('Colorbox link'),
'field types' => array('text', 'computed'),
'field types' => array('text', 'computed', 'entityreference'),
'settings' => array(
'colorbox_field_formatter_style' => 'colorbox-load',
'colorbox_field_formatter_link_type' => 'content',
......@@ -181,52 +181,67 @@ function colorbox_field_formatter_field_formatter_settings_summary($field, $inst
*/
function colorbox_field_formatter_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
$settings = $display['settings'];
if (isset($items[0])) {
if (isset($items[0]['safe_value'])) {
$output = $items[0]['safe_value'];
}
else if (isset($items[0]['value'])) {
$output = $items[0]['value'];
}
}
$element = array();
if (!empty($output)) {
if ($settings['colorbox_field_formatter_link_type'] == 'content') {
$uri = entity_uri($entity_type, $entity);
foreach ($items as $delta => $item) {
$uri = FALSE;
if (isset($item['safe_value'])) {
$output = $item['safe_value'];
}
else {
$link = module_exists('token') ? token_replace($settings['colorbox_field_formatter_link'], array($entity_type => $entity)) : $settings['colorbox_field_formatter_link'];
$uri = array('path' => $link);
}
$options = array(
'html' => TRUE,
'attributes' => array(
'class' => array($settings['colorbox_field_formatter_style']),
),
'query' => array(
'width' => $settings['colorbox_field_formatter_width'],
'height' => $settings['colorbox_field_formatter_height'],
),
);
if ($settings['colorbox_field_formatter_iframe']) {
$options['query']['iframe'] = 'true';
else if (isset($item['value'])) {
$output = $item['value'];
}
if (!empty($settings['colorbox_field_formatter_anchor'])) {
$options['query']['fragment'] = $settings['colorbox_field_formatter_anchor'];
else if (isset($item['target_id'])) {
$target = entity_load($instance['entity_type'], array($item['target_id']));
if (is_array($target)) {
$target = reset($target);
}
$output = entity_label($instance['entity_type'], $target);
$uri = entity_uri($instance['entity_type'], $target);
}
if (!empty($settings['colorbox_field_formatter_class'])) {
$options['attributes']['class'] = array_merge($options['attributes']['class'], explode(' ', $settings['colorbox_field_formatter_class']));
else {
$output = FALSE;
}
$output = l($output, $uri['path'], $options);
$element = array(
array(
if (!empty($output)) {
if (!$uri) {
if ($settings['colorbox_field_formatter_link_type'] == 'content') {
$uri = entity_uri($entity_type, $entity);
}
else {
$link = module_exists('token') ? token_replace($settings['colorbox_field_formatter_link'], array($entity_type => $entity)) : $settings['colorbox_field_formatter_link'];
$uri = array('path' => $link);
}
}
$options = array(
'html' => TRUE,
'attributes' => array(
'class' => array($settings['colorbox_field_formatter_style']),
),
'query' => array(
'width' => $settings['colorbox_field_formatter_width'],
'height' => $settings['colorbox_field_formatter_height'],
),
);
if ($settings['colorbox_field_formatter_iframe']) {
$options['query']['iframe'] = 'true';
}
if (!empty($settings['colorbox_field_formatter_anchor'])) {
$options['query']['fragment'] = $settings['colorbox_field_formatter_anchor'];
}
if (!empty($settings['colorbox_field_formatter_class'])) {
$options['attributes']['class'] = array_merge($options['attributes']['class'], explode(' ', $settings['colorbox_field_formatter_class']));
}
$output = l($output, $uri['path'], $options);
$element[$delta] = array(
'#markup' => $output,
),
);
);
}
}
return $element;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment