You are here

function beautytips_manager_custom_styles_form in BeautyTips 7.2

Form for editing a custom beautytip style.

1 string reference to 'beautytips_manager_custom_styles_form'
beautytips_manager_menu in ./beautytips_manager.module
Implements hook_menu().

File

./beautytips_manager.admin.inc, line 308
Administration pages and forms for beautytips manager.

Code

function beautytips_manager_custom_styles_form($form, &$form_state, $id = NULL) {
  if (!is_null($id)) {
    $style = beautytips_manager_get_custom_style($id);
    $style_map = beautytips_manager_style_mapping();
    $style_options = $style_map['options'];
    $css_style_options = $style_map['css_options'];
  }
  $form = [];
  $form['name'] = [
    '#type' => 'textfield',
    '#title' => t('Style Name'),
    '#description' => t('It must contain only alphanumeric characters and underscores.'),
    '#default_value' => isset($style->name) ? $style->name : '',
  ];
  $form['style'] = [
    '#type' => 'value',
    '#value' => isset($style) ? $style : NULL,
  ];

  // TODO: Add this into mapping
  $style_info = [
    'fill' => t('background color (string - html color)'),
    'strokeWidth' => t('width of border (integer)'),
    'strokeStyle' => t('color of border (string - html color)'),
    'width' => t('width of popup (number with px or em)'),
    'padding' => t('space between content and border (number with px em)'),
    'cornerRadius' => t('Controls roundness of corners (integer)'),
    'spikeGirth' => t('thickness of spike (integer)'),
    'spikeLength' => t('length of spike (integer)'),
    'shadowBlur' => t('Size of popup shadow (integer)'),
    'shadowColor' => t('Color of popup shadow (string - html color)'),
  ];
  $form['custom_styles'] = [
    '#type' => 'fieldset',
    '#title' => t('Custom Style Options'),
    '#description' => t('<div id="beautytips-popup-changes"><div id="beauty-click-text"><p></p></div></div>'),
    '#attributes' => [
      'class' => [
        'bt-custom-styles',
      ],
    ],
    '#tree' => TRUE,
  ];
  foreach ($style_info as $option => $description) {
    $form['custom_styles'][$option] = [
      '#title' => $option,
      '#description' => $description,
      '#type' => 'textfield',
      '#default_value' => isset($style_options) && isset($style->{$style_options[$option]}) && !is_null($style->{$style_options[$option]}) ? $style->{$style_options[$option]} : '',
    ];
  }
  $form['custom_styles']['shadow'] = [
    '#title' => 'shadow',
    '#description' => t('Whether or not the popup has a shadow'),
    '#type' => 'radios',
    '#options' => [
      'default' => t('Default'),
      'shadow' => t('Shadow On'),
      'no_shadow' => t('Shadow Off'),
    ],
    '#attributes' => [
      'class' => [
        'beautytips-options-shadow',
      ],
    ],
    '#default_value' => isset($style->shadow) ? $style->shadow : 'default',
  ];
  $form['custom_styles']['cssClass'] = [
    '#title' => 'cssClass',
    '#description' => t('The class that will be applied to the box wrapper div (of the TIP)'),
    '#type' => 'textfield',
    '#default_value' => isset($style->css_class) ? $style->css_class : '',
  ];
  $css_style_info = [
    'color',
    'fontFamily',
    'fontWeight',
    'fontSize',
  ];
  $form['custom_styles']['css-styles'] = [
    '#type' => 'fieldset',
    '#title' => t('Font Styling'),
    '#description' => t('Enter css options for changing the font style'),
    '#attributes' => [
      'class' => [
        'beautytips-css-styling',
      ],
    ],
    '#collapsible' => FALSE,
  ];
  foreach ($css_style_info as $option) {
    $form['custom_styles']['css-styles'][$option] = [
      '#title' => $option,
      '#type' => 'textfield',
      '#default_value' => isset($css_style_options) && isset($style->{$css_style_options[$option]}) && !is_null($style->{$css_style_options[$option]}) ? $style->{$css_style_options[$option]} : '',
    ];
  }
  $path = drupal_get_path('module', 'beautytips');

  // TODO: This could be in a library
  drupal_add_js($path . '/other_libs/colorpicker/js/colorpicker.js');
  drupal_add_css($path . '/other_libs/colorpicker/css/colorpicker.css');
  beautytips_add_beautytips();
  drupal_add_js($path . '/js/bt_custom_styles.js');
  $form['save'] = [
    '#type' => 'submit',
    '#value' => t('Save'),
  ];
  return $form;
}