linkimagefield.module in Link Image Field 8
Same filename and directory in other branches
Defines theming for a link image field.
File
linkimagefield.moduleView source
<?php
/**
* @file
* Defines theming for a link image field.
*/
/**
* Implements hook_theme().
*/
function linkimagefield_theme() {
return array(
'linkimage_formatter' => array(
'template' => 'linkimage_formatter',
'render element' => 'element',
),
);
}
/**
* Prepares variables for linkimagefield formatter template.
*
* @param $variables
* An associative array containing:
* - element: An array of elements to display in formatter.
* - image_style: An optional image style.
* - item_attributes: An array of image attributes.
*
* @ingroup themeable
*/
function template_preprocess_linkimage_formatter(&$variables) {
$element = $variables['element'];
if ($element['#image_style']) {
$image = array(
'#theme' => 'image_style',
'#style_name' => $element['#image_style'],
);
}
else {
$image = array(
'#theme' => 'image',
);
}
$image['#attributes'] = $element['#item_attributes'];
$item = $element['#item'];
// Do not output an empty 'title' attribute.
if (drupal_strlen($item->title) != 0) {
$image['#title'] = $item->title;
}
if (($entity = $item->entity) && empty($item->uri)) {
$image['#uri'] = $entity
->getFileUri();
}
else {
$image['#uri'] = $item->uri;
}
foreach (array(
'width',
'height',
'alt',
) as $key) {
$image["#{$key}"] = $item->{$key};
}
$variables['image'] = drupal_render($image);
$variables['attributes'] = array(
'title' => $item->title,
'target' => $item->target,
'rel' => $item->rel,
'class' => $item->class,
);
$variables['url'] = $item->url;
}
/**
* The list of URL frame targets.
*
* @return array
*/
function _linkimagefield_widget_url_target_options() {
return array(
'_self' => t('Same Window (_self)'),
'_blank' => t('New Window (_blank)'),
'_parent' => t('Parent Frame (_parent)'),
'_top' => t('Top Frame (_top)'),
);
}
Functions
Name | Description |
---|---|
linkimagefield_theme | Implements hook_theme(). |
template_preprocess_linkimage_formatter | Prepares variables for linkimagefield formatter template. |
_linkimagefield_widget_url_target_options | The list of URL frame targets. |