function resp_img_field_formatter_settings_form_alter in Responsive images and styles 8
Implements hook_field_formatter_settings_form_alter().
File
- ./
resp_img.module, line 279
Code
function resp_img_field_formatter_settings_form_alter(&$element, &$form_state, $context) {
if (isset($context['field']['type']) && $context['field']['type'] === 'image') {
$settings = $context['instance']['display'][$context['view_mode']]['settings'];
$theme_breakpoints = breakpoints_breakpoint_load_all_active();
if (!empty($theme_breakpoints)) {
$element['resp_img_responsive'] = array(
'#type' => 'checkbox',
'#title' => t('Go responsive'),
'#default_value' => isset($settings['resp_img_responsive']) ? $settings['resp_img_responsive'] : FALSE,
// @todo: needs better wording
'#description' => t('If you enable this, you can select an image style for each defined breakpoint/breakpoint.<br />
The image style at the top will be used as default/fallback.<br />
If you leave all dropdowns empty the logic will try to use the default breakpoint.'),
);
$element['resp_img'] = array(
'#type' => 'container',
'#states' => array(
'invisible' => array(
'input[name="fields[field_image][settings_edit_form][settings][resp_img_responsive]"]' => array(
'checked' => FALSE,
),
),
),
);
$image_styles = image_style_options(TRUE);
foreach ($theme_breakpoints as $breakpoint_name => $breakpoint) {
$label = $breakpoint->name . ' [' . $breakpoint->breakpoint . ']';
$element['resp_img'][$breakpoint_name]['1x'] = array(
'#title' => check_plain($label),
'#type' => 'select',
'#options' => $image_styles,
'#default_value' => isset($settings['resp_img'][$breakpoint_name]['1x']) ? $settings['resp_img'][$breakpoint_name]['1x'] : '',
);
if (isset($breakpoint->multipliers) && !empty($breakpoint->multipliers)) {
foreach ($breakpoint->multipliers as $multiplier => $value) {
if ($multiplier != '1x' && $value) {
$element['resp_img'][$breakpoint_name][$multiplier] = array(
'#title' => check_plain($multiplier . ' ' . $label),
'#type' => 'select',
'#options' => $image_styles,
'#default_value' => isset($settings['resp_img'][$breakpoint_name][$multiplier]) ? $settings['resp_img'][$breakpoint_name][$multiplier] : '',
);
}
}
}
}
}
}
}