Commit 33786876 authored by jurgenhaas's avatar jurgenhaas

Initial commit.

parents
name = "Colorbox Field Formatter"
description = "todo"
core = "7.x"
package = "colorbox"
dependencies[] = "colorbox"
<?php
/**
* @file
* Implement a colorbox field formater for proper links.
*/
/**
* Implements hook_field_formatter_info().
*/
function colorbox_field_formatter_field_formatter_info() {
return array(
'colorbox_field_formatter_linked' => array(
'label' => t('Colorbox link'),
'field types' => array('text'),
'settings' => array(
'colorbox_field_formatter_style' => 'colorbox-load',
'colorbox_field_formatter_link_type' => 'content',
'colorbox_field_formatter_link' => '',
'colorbox_field_formatter_width' => '500',
'colorbox_field_formatter_height' => '500',
'colorbox_field_formatter_iframe' => 0,
'colorbox_field_formatter_anchor' => '',
),
),
);
}
/**
* Implements hook_field_formatter_settings_form().
*/
function colorbox_field_formatter_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
$settings = $instance['display'][$view_mode]['settings'];
$element = array();
$styles = array();
if (variable_get('colorbox_load', 0)) {
$styles['colorbox-load'] = t('Colorbox load');
$default_style = 'colorbox-load';
}
if (variable_get('colorbox_inline', 0)) {
$styles['colorbox-inline'] = t('Colorbox inline');
$default_style = 'colorbox-inline';
}
if (module_exists('colorbox_node')) {
$styles['colorbox-node'] = t('Colorbox node');
$default_style = 'colorbox-node';
}
$element['colorbox_field_formatter_style'] = array(
'#title' => t('Style of colorbox'),
'#type' => 'select',
'#default_value' => !empty($settings['colorbox_field_formatter_style']) ? $settings['colorbox_field_formatter_style'] : $default_style,
'#options' => $styles,
);
$link_types = array(
'content' => t('Content'),
);
$element['colorbox_field_formatter_link_type'] = array(
'#title' => t('Link colorbox to'),
'#type' => 'select',
'#default_value' => $settings['colorbox_field_formatter_link_type'],
'#options' => $link_types,
);
$element['colorbox_field_formatter_link'] = array(
'#title' => t('URI'),
'#type' => 'textfield',
'#default_value' => $settings['colorbox_field_formatter_link'],
);
$element['colorbox_field_formatter_width'] = array(
'#title' => t('Width'),
'#type' => 'textfield',
'#default_value' => $settings['colorbox_field_formatter_width'],
);
$element['colorbox_field_formatter_height'] = array(
'#title' => t('Height'),
'#type' => 'textfield',
'#default_value' => $settings['colorbox_field_formatter_height'],
);
$element['colorbox_field_formatter_iframe'] = array(
'#title' => t('iFrame Mode'),
'#type' => 'checkbox',
'#default_value' => $settings['colorbox_field_formatter_iframe'],
);
$element['colorbox_field_formatter_anchor'] = array(
'#title' => t('Anchor'),
'#type' => 'textfield',
'#default_value' => $settings['colorbox_field_formatter_anchor'],
);
return $element;
}
/**
* Implements hook_field_formatter_settings_summary().
*/
function colorbox_field_formatter_field_formatter_settings_summary($field, $instance, $view_mode) {
$settings = $instance['display'][$view_mode]['settings'];
$summary = array();
// TODO: Go through the settings.
$summary[] = t('We will collect settings here');
return implode('<br />', $summary);
}
/**
* Implements hook_field_formatter_view().
*/
function colorbox_field_formatter_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
$settings = $display['settings'];
$output = isset($items[0]) ? $items[0]['safe_value'] : '';
$element = array();
if (!empty($output)) {
if ($settings['colorbox_field_formatter_link_type'] == 'content') {
$uri = entity_uri($entity_type, $entity);
}
else {
$uri = array('path' => $settings['colorbox_field_formatter_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'];
}
$output = l($output, $uri['path'], $options);
$element = array(
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