You are here

function site_banner_generate_text_color_form_elements in Site Banner 7

Generates the form elements for defining text colors.

Parameters

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

Return value

array A Drupal form array populating form elements for site banner text color

2 calls to site_banner_generate_text_color_form_elements()
SiteBannerContextReactionChangeBannerTextColor::options_form in ./site_banner_context_reaction_functions.inc
Administration panel for setting banner text 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 225

Code

function site_banner_generate_text_color_form_elements($existing_text_color) {

  // Setup text color settings.
  $text_color_array = site_banner_get_text_colors();
  $text_color_array_names = array_values($text_color_array);
  $selected_text_index = 1;
  $using_custom_text_color = TRUE;

  // Check if background color is a preset color.
  if (in_array($existing_text_color, array_keys($text_color_array), TRUE)) {
    $using_custom_text_color = FALSE;

    // Using an existing color: find its name.
    $text_color_to_search = $text_color_array[$existing_text_color];
    $selected_text_index = array_search($text_color_to_search, $text_color_array_names, TRUE);
  }

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