function picture_mapping_form in Picture 7.2
Build picture mapping form.
1 string reference to 'picture_mapping_form'
- picture_picture_mapping_ctools_export_ui in ctools/
plugins/ export_ui/ picture_mapping.inc - Implements HOOK_PLUGIN_ctools_export_ui().
File
- ./
picture.admin.inc, line 59 - Picture - map breakpoints and image styles.
Code
function picture_mapping_form(&$form, &$form_state) {
$picture_mapping = $form_state['item'];
$form['info']['label']['#required'] = TRUE;
$form['info']['machine_name']['#title'] = t('Machine name');
$groups = breakpoints_breakpoint_group_load_all();
$options = array();
foreach ($groups as $group) {
$options[$group->machine_name] = $group->name;
}
$form['breakpoint_group'] = array(
'#title' => t('Breakpoint group'),
'#type' => 'select',
'#required' => TRUE,
'#description' => t('Select a breakpoint group.'),
'#options' => $options,
'#default_value' => $picture_mapping
->getBreakpointGroup()->machine_name,
'#ajax' => array(
'callback' => 'picture_mapping_form_change_breakpoint_group',
'wrapper' => 'picture-mapping-container',
'method' => 'replace',
'effect' => 'fade',
),
);
$form['mapping'] = array(
'#type' => 'container',
'#attributes' => array(
'id' => 'picture-mapping-container',
),
'#tree' => TRUE,
);
$image_styles = image_style_options(TRUE) + array(
PICTURE_EMPTY_IMAGE => t('Empty image'),
PICTURE_ORIGINAL_IMAGE => t('Original image'),
);
foreach ($picture_mapping
->getMappings() as $breakpoint_id => $mapping) {
foreach ($mapping as $multiplier => $mapping_definition) {
$breakpoint = breakpoints_breakpoint_load_by_fullkey($breakpoint_id);
$label = $multiplier . ' ' . $breakpoint->name . ' [' . $breakpoint->breakpoint . ']';
$form['mapping'][$breakpoint_id][$multiplier] = array(
'#type' => 'fieldset',
'#title' => check_plain($label),
);
$form['mapping'][$breakpoint_id][$multiplier]['mapping_type'] = array(
'#title' => t('Type'),
'#type' => 'radios',
'#options' => array(
'_none' => t('Do not use this breakpoint'),
'image_style' => t('Use image styles'),
'sizes' => t('Use the sizes attribute'),
),
'#default_value' => isset($mapping_definition['mapping_type']) ? $mapping_definition['mapping_type'] : '_none',
);
$form['mapping'][$breakpoint_id][$multiplier]['image_style'] = array(
'#type' => 'select',
'#title' => t('Image style'),
'#options' => $image_styles,
'#maxlength' => 1024,
'#default_value' => isset($mapping_definition['image_style']) ? $mapping_definition['image_style'] : '',
'#description' => t('Select an image style for this breakpoint.'),
'#states' => array(
'visible' => array(
':input[name="mapping[' . $breakpoint_id . '][' . $multiplier . '][mapping_type]"]' => array(
'value' => 'image_style',
),
),
),
);
$form['mapping'][$breakpoint_id][$multiplier]['sizes'] = array(
'#type' => 'textfield',
'#title' => t('Sizes'),
'#default_value' => isset($mapping_definition['sizes']) ? $mapping_definition['sizes'] : '',
'#description' => t('Enter the value for the sizes attribute (e.g. "(min-width:700px) 700px, 100vw").'),
'#states' => array(
'visible' => array(
':input[name="mapping[' . $breakpoint_id . '][' . $multiplier . '][mapping_type]"]' => array(
'value' => 'sizes',
),
),
),
);
$form['mapping'][$breakpoint_id][$multiplier]['sizes_image_styles'] = array(
'#title' => t('Image styles'),
'#type' => 'checkboxes',
'#options' => array_diff_key($image_styles, array(
'' => '',
)),
'#default_value' => isset($mapping_definition['sizes_image_styles']) ? $mapping_definition['sizes_image_styles'] : array(),
'#states' => array(
'visible' => array(
':input[name="mapping[' . $breakpoint_id . '][' . $multiplier . '][mapping_type]"]' => array(
'value' => 'sizes',
),
),
),
);
}
}
$form['#tree'] = FALSE;
return $form;
}