public function CustomStylesEditForm::buildForm in BeautyTips 8
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form structure.
Overrides FormInterface::buildForm
File
- beautytips_manager/
src/ Form/ CustomStylesEditForm.php, line 22
Class
Namespace
Drupal\beautytips_manager\FormCode
public function buildForm(array $form, FormStateInterface $form_state, $id = NULL) {
if (!is_null($id)) {
$this->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($this->style->name) ? $this->style->name : '',
];
// 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($this->style->{$style_options[$option]}) && !is_null($this->style->{$style_options[$option]}) ? $this->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($this->style->shadow) ? $this->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($this->style->css_class) ? $this->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($this->style->{$css_style_options[$option]}) && !is_null($this->style->{$css_style_options[$option]}) ? $this->style->{$css_style_options[$option]} : '',
];
}
beautytips_add_beautytips($form);
$form['#attached']['library'][] = 'beautytips_manager/colorpicker';
$form['#attached']['library'][] = 'beautytips/beautytips.bt-custom-style';
$form['save'] = [
'#type' => 'submit',
'#value' => t('Save'),
];
return $form;
}