You are here

function site_banner_generate_bg_color_form_elements in Site Banner 7

Generates the form elements for defining background colours.

Parameters

string $existing_background_color: the existing color as a HTML hexadecimal color code.

Return value

array A Drupal form array populating form elements for banner background color.

2 calls to site_banner_generate_bg_color_form_elements()
SiteBannerContextReactionChangeBannerBackgroundColor::options_form in ./site_banner_context_reaction_functions.inc
Admin panel for setting banner background color for selected contexts.
site_banner_admin_settings_form in ./site_banner.admin.inc
Implements hook_form_FORM_ID() for node_type_form().

File

./site_banner.admin.inc, line 156

Code

function site_banner_generate_bg_color_form_elements($existing_background_color) {
  $form = array();

  // Setup background color settings.
  $background_color_array = site_banner_get_background_colors();
  $background_color_array_names = array_values($background_color_array);
  $selected_background_index = 1;
  $using_custom_background_color = TRUE;

  // Check if background color is a preset color.
  if (in_array($existing_background_color, array_keys($background_color_array), TRUE)) {
    $using_custom_background_color = FALSE;

    // Using an existing color: find its name.
    $background_color_to_search = $background_color_array[$existing_background_color];
    $selected_background_index = array_search($background_color_to_search, $background_color_array_names, TRUE);
  }

  // Setup form elements.
  $form['site_banner_background_color_select'] = array(
    '#type' => 'checkbox',
    '#title' => t('Select a custom background color'),
    '#description' => t('Checking this box will allow you to define a custom background color for the site banner.'),
    '#default_value' => $using_custom_background_color,
  );
  $form['site_banner_background_color_form'] = array(
    '#title' => t('Banner background color'),
    '#description' => t('The background color for the site banner.'),
    '#type' => 'select',
    '#options' => $background_color_array_names,
    '#default_value' => $selected_background_index,
    '#required' => FALSE,
    '#states' => array(
      'visible' => array(
        ':input[name="site_banner_background_color_select"]' => array(
          'checked' => FALSE,
        ),
      ),
    ),
  );
  $form['site_banner_background_custom_color_form'] = array(
    '#title' => t('Custom background color'),
    '#description' => t("A custom color code in hexadecimal format (for example #000000 for black) for the banner's custom background color."),
    '#type' => 'textfield',
    '#default_value' => $existing_background_color,
    '#size' => 7,
    '#maxlength' => 7,
    '#required' => FALSE,
    '#states' => array(
      'visible' => array(
        ':input[name="site_banner_background_color_select"]' => array(
          'checked' => TRUE,
        ),
      ),
    ),
  );
  return $form;
}