function amp_field_formatter_settings_form in Accelerated Mobile Pages (AMP) 7
Implements hook_field_formatter_settings_form().
File
- ./
amp.module, line 968
Code
function amp_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
$display = $instance['display'][$view_mode];
$settings = $display['settings'];
$element = array();
if (strpos($display['type'], '_trimmed') !== FALSE) {
$element['trim_length'] = array(
'#title' => t('Trimmed limit'),
'#type' => 'textfield',
'#field_suffix' => t('characters'),
'#size' => 10,
'#default_value' => $settings['trim_length'],
'#element_validate' => array(
'element_validate_integer_positive',
),
'#description' => t('If the summary is not set, the trimmed %label field will be shorter than this character limit.', array(
'%label' => $instance['label'],
)),
'#required' => TRUE,
);
}
if ($display['type'] == 'amp_image') {
$image_styles = image_style_options(FALSE, PASS_THROUGH);
$element['image_style'] = array(
'#title' => t('Image style'),
'#type' => 'select',
'#default_value' => $settings['image_style'],
'#empty_option' => t('None (original image)'),
'#options' => $image_styles,
);
$link_types = array(
'content' => t('Content'),
'file' => t('File'),
);
$element['image_link'] = array(
'#title' => t('Link image to'),
'#type' => 'select',
'#default_value' => $settings['image_link'],
'#empty_option' => t('Nothing'),
'#options' => $link_types,
);
$layout_url = 'https://www.ampproject.org/docs/guides/responsive/control_layout.html#size-and-position-elements';
$layout_options = _amp_get_layouts();
$element['amp_layout'] = array(
'#title' => t('AMP Layout'),
'#type' => 'select',
'#default_value' => $settings['amp_layout'],
'#empty_option' => t('None (no layout)'),
'#options' => $layout_options,
'#description' => t('<a href="@url" target="_blank">Layout Information</a>', array(
'@url' => $layout_url,
)),
'#required' => TRUE,
);
$element['amp_fixed_height'] = array(
'#title' => t('Layout Height (used for fixed-height only)'),
'#type' => 'textfield',
'#states' => array(
'visible' => array(
':input[name="fields[' . $field['field_name'] . '][settings_edit_form][settings][amp_layout]"]' => array(
'value' => 'fixed-height',
),
),
),
'#size' => 10,
'#default_value' => $settings['amp_fixed_height'],
);
}
if ($display['type'] == 'amp_video') {
$element['amp_video_height'] = array(
'#title' => t('Height'),
'#type' => 'textfield',
'#size' => 10,
'#default_value' => $settings['amp_video_height'],
'#element_validate' => array(
'element_validate_integer_positive',
),
'#description' => t('The height of the video is used to determine the aspect ratio in a responsive layout.'),
'#required' => TRUE,
);
$element['amp_video_width'] = array(
'#title' => t('Width'),
'#type' => 'textfield',
'#size' => 10,
'#default_value' => $settings['amp_video_width'],
'#element_validate' => array(
'element_validate_integer_positive',
),
'#description' => t('The width of the video is used to determine the aspect ratio in a responsive layout.'),
'#required' => TRUE,
);
}
return $element;
}