function acquia_lift_profiles_thumbnail_entity_settings_form in Acquia Lift Connector 7
Same name and namespace in other branches
- 7.2 acquia_lift_profiles/acquia_lift_profiles.admin.inc \acquia_lift_profiles_thumbnail_entity_settings_form()
Administrative form to select the thumbnail image to use per content type/ entity bundle.
@bundle The bundle name to select from.
Parameters
$entity_name: The name of the entity type, e.g., node.
entity: The entity data object.
1 call to acquia_lift_profiles_thumbnail_entity_settings_form()
- acquia_lift_profiles_form_node_type_form_alter in acquia_lift_profiles/
acquia_lift_profiles.module - Implements hook_form_FORM_ID_alter().
File
- acquia_lift_profiles/
acquia_lift_profiles.admin.inc, line 282 - acquia_lift_profiles.admin.inc Provides functions needed for the admin UI.
Code
function acquia_lift_profiles_thumbnail_entity_settings_form(&$form, &$form_state, $entity_name, $entity, $bundle) {
// If the entity is not fieldable, check that there is at least one bundle
// with an image field.
$options = acquia_lift_profiles_thumbnail_available_fields($entity_name, $bundle);
if (!$entity['fieldable']) {
if (count($options) == 0) {
return;
}
}
$styles = image_styles();
$style_options = array();
foreach ($styles as $style) {
$style_options[$style['name']] = t($style['label']);
}
$form['#attached']['js'][] = drupal_get_path('module', 'acquia_lift_profiles') . '/js/acquia_lift_profiles.admin.js';
$form['acquia_lift_profiles'] = array(
'#type' => 'fieldset',
'#title' => t('Acquia Lift Profiles'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#tree' => TRUE,
);
$form['acquia_lift_profiles']['entity'] = array(
'#type' => 'value',
'#value' => $entity_name,
);
$form['acquia_lift_profiles']['bundle'] = array(
'#type' => 'value',
'#value' => $bundle,
);
$form['acquia_lift_profiles']['thumbnail'] = array(
'#type' => 'select',
'#title' => t('Select preview image to use for content recommendations.'),
'#options' => $options,
'#empty_option' => t('None'),
'#empty_value' => '',
'#default_value' => acquia_lift_profiles_thumbnail_get_field($entity_name, $bundle),
);
$image_style_fields = acquia_lift_profiles_thumbnail_available_fields($entity_name, $bundle, TRUE);
$form['acquia_lift_profiles']['style'] = array(
'#type' => 'select',
'#title' => t('Select the style to use for the thumbnail'),
'#options' => $style_options,
'#default_value' => acquia_lift_profiles_thumbnail_get_style_field($entity_name, $bundle),
);
// If no available fields support styles then hide the style selector.
if (empty($image_style_fields)) {
$form['acquia_lift_profiles']['style']['#type'] = 'value';
$form['acquia_lift_profiles']['style']['#value'] = '';
}
else {
// Hide the image style field if the thumbnail isn't in the fields that
// supports image styles. In order to list multiple negatives we use the
// workaround: https://api.drupal.org/api/drupal/includes!common.inc/function/drupal_process_states/7#comment-24708
foreach ($image_style_fields as $key => $value) {
$form['acquia_lift_profiles']['style']['#states']['invisible'][':input[name="acquia_lift_profiles[thumbnail]"], allow-multiple-' . $key] = array(
'!value' => $key,
);
}
}
// If there are no available image fields at all, disable the selection
// and hide the style selector.
if (!count($options)) {
$form['acquia_lift_profiles']['thumbnail']['#disabled'] = TRUE;
$form['acquia_lift_profiles']['thumbnail']['#description'] = t('You must define at least one image field to enable the content recommendations thumbnail image.');
// Make the style hidden completely.
$form['acquia_lift_profiles']['style']['#type'] = 'value';
$form['acquia_lift_profiles']['style']['#value'] = '';
}
$form['#submit'][] = 'acquia_lift_profiles_entity_settings_form_submit';
}