function _focal_point_preview in Focal Point 7
Allows previewing of derivitive images based on the given focal point.
Return a render array that shows the derivative images of the given fid using the given focal point for every style that uses a focal point effect.
Parameters
int $fid: The fid of the file entity in question.
string $focal_point: A focal point value.
bool $show_original: (Optional) If TRUE the original image will be displayed above the preview images.
Return value
array A render array to display the preview page.
2 calls to _focal_point_preview()
- focal_point_preview_page in ./
focal_point.admin.inc - Page callback function.
- focal_point_test_drive_form in ./
focal_point.admin.inc - Form builder for the "test drive" page.
File
- ./
focal_point.module, line 738
Code
function _focal_point_preview($fid, $focal_point, $show_original = TRUE) {
$file = is_numeric($fid) ? file_load($fid) : NULL;
$output = array();
// Using the example image, show every image style that uses a focal point
// effect.
$output['focal_point_examples'] = array(
'#theme_wrappers' => array(
'container',
),
'#attributes' => array(
'class' => array(
'focal_point_examples',
),
),
);
if ($file) {
if ($show_original) {
$output['focal_point_examples']['original'] = array(
'#type' => 'markup',
'#prefix' => '<h2>' . t('Original Image') . '</h2>',
'#theme' => 'image',
'#path' => $file->uri,
'#theme_wrappers' => array(
'container',
),
'#attributes' => array(
'class' => array(
'focal-point-preview--original',
),
),
);
}
$styles = _focal_point_get_image_styles();
if (!empty($styles)) {
foreach ($styles as $isid => $style) {
if (module_exists('borealis') && strpos($style['name'], 'borealis') === 0) {
// Don't output borealis styles; there are just too many.
continue;
}
// The 'label' property was not introduced until Drupal 7.23 so just in
// case we provide a fallback.
// @see https://www.drupal.org/node/2350147
$label = isset($style['label']) ? $style['label'] : $style['name'];
$output['focal_point_examples'][$isid] = array(
'#type' => 'markup',
'#prefix' => '<h2>' . $label . '</h2>',
'#theme' => 'focal_point_image_style',
'#style_name' => $style['name'],
'#path' => $file->uri,
'#focal_point' => $focal_point,
'#theme_wrappers' => array(
'container',
),
'#attributes' => array(
'class' => array(
'focal-point-preview--' . $style['name'],
),
),
);
}
}
else {
$output['focal_point_examples']['#markup'] = '<div class="messages warning">' . t('There are no styles defined that use a focal point effect. To see how this module will work you should <a href="@url">create a new image style</a> that uses one.', array(
'@url' => url('/admin/config/media/image-styles'),
)) . '</div>';
}
}
return $output;
}