You are here

function textimage_text_effect_form in Textimage 7.3

Settings for 'textimage_text' image effect.

Implements hook_form().

Parameters

array $data: The current configuration for this image effect.

Return value

array The form definition for this effect.

1 string reference to 'textimage_text_effect_form'
textimage_image_effect_info in ./textimage.module
Implements hook_image_effect_info().

File

effects/textimage_text.inc, line 67
Implementation of the 'textimage_text' image effect.

Code

function textimage_text_effect_form($data) {

  // Merge input data with effect defaults.
  $data = drupal_array_merge_deep(_textimage_text_effect_defaults(), $data);
  $form = array();

  // Preview effect.
  $data['preview_bar']['debug_visuals'] = isset($data['preview_bar']['debug_visuals']) ? $data['preview_bar']['debug_visuals'] : FALSE;
  $form['preview'] = array(
    '#type' => 'item',
    '#markup' => '<strong>' . t('Preview') . ":</strong>\n" . '<div id="textimage-preview">' . _textimage_text_effect_preview_image($data) . '</div>',
  );

  // Preview bar.
  $form['preview_bar'] = array(
    '#type' => 'container',
    '#attributes' => array(
      'class' => array(
        'container-inline',
      ),
    ),
  );

  // Refresh button.
  $form['preview_bar']['preview'] = array(
    '#type' => 'button',
    '#value' => t('Refresh preview'),
    '#ajax' => array(
      'callback' => '_textimage_text_effect_form_ajax',
    ),
  );

  // Visual aids.
  $form['preview_bar']['debug_visuals'] = array(
    '#type' => 'checkbox',
    '#title' => t('Visual aids in preview'),
    '#default_value' => FALSE,
  );

  // Settings.
  $form['settings'] = array(
    '#type' => 'vertical_tabs',
  );

  // ---- Text default.
  $form['settings']['text_default'] = array(
    '#type' => 'fieldset',
    '#title' => t('Text default'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $form['settings']['text_default']['text_string'] = array(
    '#type' => 'textarea',
    '#title' => t('Default text'),
    '#default_value' => $data['text_string'],
    '#description' => t('Enter the default text string for this effect. You can also enter tokens, that Textimage will resolve when applying the effect.'),
    '#rows' => 3,
    '#required' => TRUE,
  );
  if (_textimage_module_exists('token', TEXTIMAGE_TOKEN_MIN_VERSION)) {
    $form['settings']['text_default']['tokens'] = array(
      '#theme' => 'token_tree',
      '#token_types' => array(
        'node',
        'user',
        'file',
        'textimage',
      ),
      '#global_types' => TRUE,
      '#click_insert' => TRUE,
    );
  }

  // ---- Font settings.
  $form['settings']['font'] = array(
    '#type' => 'fieldset',
    '#title' => t('Font settings'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $font_options = drupal_map_assoc(TextimageFonts::getList());
  $form['settings']['font']['name'] = array(
    '#type' => 'select',
    '#title' => t('Font'),
    '#options' => $font_options,
    '#default_value' => $data['font']['name'],
    '#description' => t('Select the font to be used in this image. If no fonts are listed, check the <a href="!path">settings for Fonts</a>.', array(
      '!path' => url('admin/config/media/textimage/settings'),
    )),
    '#required' => TRUE,
  );
  $form['settings']['font']['size'] = array(
    '#type' => 'textfield',
    '#title' => t('Size'),
    '#description' => t('Enter the size of the text to be generated.'),
    '#default_value' => $data['font']['size'],
    '#maxlength' => 5,
    '#size' => 3,
    '#required' => TRUE,
    '#element_validate' => array(
      'element_validate_integer_positive',
    ),
  );
  $form['settings']['font']['angle'] = array(
    '#type' => 'textfield',
    '#title' => t('Rotation'),
    '#maxlength' => 4,
    '#size' => 4,
    '#field_suffix' => t('&deg;'),
    '#description' => t('Enter the angle in degrees at which the text will be displayed. Positive numbers rotate the text clockwise, negative numbers counter-clockwise.'),
    '#default_value' => $data['font']['angle'],
    '#element_validate' => array(
      'element_validate_number',
    ),
  );
  $form['settings']['font']['color'] = array(
    '#type' => 'textimage_color',
    '#title' => t('Font color'),
    '#description' => t('Set the font color.'),
    '#allow_opacity' => TRUE,
    '#default_value' => $data['font']['color'],
  );

  // Outline.
  $form['settings']['font']['stroke'] = array(
    '#type' => 'fieldset',
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#title' => t('Outline / Shadow'),
    '#description' => t('Optionally add an outline or shadow around the font. Enter the information in pixels.'),
  );
  $stroke_options = array(
    'outline' => t('Outline'),
    'shadow' => t('Shadow'),
  );
  $form['settings']['font']['stroke']['mode'] = array(
    '#type' => 'radios',
    '#title' => t('Mode'),
    '#options' => $stroke_options,
    '#default_value' => $data['font']['stroke_mode'],
  );
  $form['settings']['font']['stroke']['top'] = array(
    '#type' => 'textfield',
    '#title' => t('Top'),
    '#default_value' => $data['font']['outline_top'],
    '#maxlength' => 2,
    '#size' => 3,
    '#field_suffix' => 'px',
    '#element_validate' => array(
      'element_validate_integer',
    ),
    '#states' => array(
      'visible' => array(
        ':radio[name="data[settings][font][stroke][mode]"]' => array(
          'value' => 'outline',
        ),
      ),
    ),
  );
  $form['settings']['font']['stroke']['right'] = array(
    '#type' => 'textfield',
    '#title' => t('Right'),
    '#default_value' => $data['font']['outline_right'],
    '#maxlength' => 2,
    '#size' => 3,
    '#field_suffix' => 'px',
    '#element_validate' => array(
      'element_validate_integer',
    ),
    '#states' => array(
      'visible' => array(
        ':radio[name="data[settings][font][stroke][mode]"]' => array(
          'value' => 'outline',
        ),
      ),
    ),
  );
  $form['settings']['font']['stroke']['bottom'] = array(
    '#type' => 'textfield',
    '#title' => t('Bottom'),
    '#default_value' => $data['font']['outline_bottom'],
    '#maxlength' => 2,
    '#size' => 3,
    '#field_suffix' => 'px',
    '#element_validate' => array(
      'element_validate_integer',
    ),
    '#states' => array(
      'visible' => array(
        ':radio[name="data[settings][font][stroke][mode]"]' => array(
          'value' => 'outline',
        ),
      ),
    ),
  );
  $form['settings']['font']['stroke']['left'] = array(
    '#type' => 'textfield',
    '#title' => t('Left'),
    '#default_value' => $data['font']['outline_left'],
    '#maxlength' => 2,
    '#size' => 3,
    '#field_suffix' => 'px',
    '#element_validate' => array(
      'element_validate_integer',
    ),
    '#states' => array(
      'visible' => array(
        ':radio[name="data[settings][font][stroke][mode]"]' => array(
          'value' => 'outline',
        ),
      ),
    ),
  );
  $form['settings']['font']['stroke']['x_offset'] = array(
    '#type' => 'textfield',
    '#title' => t('Horizontal offset'),
    '#default_value' => $data['font']['shadow_x_offset'],
    '#maxlength' => 3,
    '#size' => 3,
    '#field_suffix' => 'px',
    '#element_validate' => array(
      'element_validate_integer',
    ),
    '#states' => array(
      'visible' => array(
        ':radio[name="data[settings][font][stroke][mode]"]' => array(
          'value' => 'shadow',
        ),
      ),
    ),
  );
  $form['settings']['font']['stroke']['y_offset'] = array(
    '#type' => 'textfield',
    '#title' => t('Vertical offset'),
    '#default_value' => $data['font']['shadow_y_offset'],
    '#maxlength' => 3,
    '#size' => 3,
    '#field_suffix' => 'px',
    '#element_validate' => array(
      'element_validate_integer',
    ),
    '#states' => array(
      'visible' => array(
        ':radio[name="data[settings][font][stroke][mode]"]' => array(
          'value' => 'shadow',
        ),
      ),
    ),
  );
  $form['settings']['font']['stroke']['width'] = array(
    '#type' => 'textfield',
    '#title' => t('Horizontal elongation'),
    '#default_value' => $data['font']['shadow_width'],
    '#maxlength' => 2,
    '#size' => 3,
    '#field_suffix' => 'px',
    '#element_validate' => array(
      'element_validate_integer',
    ),
    '#states' => array(
      'visible' => array(
        ':radio[name="data[settings][font][stroke][mode]"]' => array(
          'value' => 'shadow',
        ),
      ),
    ),
  );
  $form['settings']['font']['stroke']['height'] = array(
    '#type' => 'textfield',
    '#title' => t('Vertical elongation'),
    '#default_value' => $data['font']['shadow_height'],
    '#maxlength' => 2,
    '#size' => 3,
    '#field_suffix' => 'px',
    '#element_validate' => array(
      'element_validate_integer',
    ),
    '#states' => array(
      'visible' => array(
        ':radio[name="data[settings][font][stroke][mode]"]' => array(
          'value' => 'shadow',
        ),
      ),
    ),
  );
  $form['settings']['font']['stroke']['color'] = array(
    '#type' => 'textimage_color',
    '#title' => t('Color'),
    '#description' => t('Set the outline/shadow color.'),
    '#allow_opacity' => TRUE,
    '#default_value' => $data['font']['stroke_color'],
  );

  // ---- Text settings.
  $form['settings']['text'] = array(
    '#type' => 'fieldset',
    '#title' => t('Text settings'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );

  // Inner width.
  $form['settings']['text']['maximum_width'] = array(
    '#type' => 'textfield',
    '#title' => t('Maximum width'),
    '#field_suffix' => t('px'),
    '#description' => t('Maximum width of the text image, inclusive of padding. Text lines wider than this will be wrapped. Leave blank to disable wrapping. <b>Note:</b> in case of rotation, the width of the final image rendered will differ, to accommodate the rotation. If you need a strict width/height, add image resize/scale/crop effects afterwards.'),
    '#default_value' => $data['text']['maximum_width'],
    '#maxlength' => 4,
    '#size' => 4,
    '#element_validate' => array(
      'element_validate_integer',
    ),
  );
  $form['settings']['text']['fixed_width'] = array(
    '#type' => 'checkbox',
    '#title' => t('Fixed width?'),
    '#description' => t('If checked, the width will always be equal to the maximum width.'),
    '#default_value' => $data['text']['fixed_width'],
    '#states' => array(
      'visible' => array(
        ':input[name="data[settings][text][maximum_width]"]' => array(
          'filled' => TRUE,
        ),
      ),
    ),
  );

  // Text alignment.
  $form['settings']['text']['align'] = array(
    '#type' => 'select',
    '#title' => t('Text alignment'),
    '#options' => array(
      'left' => t('Left'),
      'center' => t('Center'),
      'right' => t('Right'),
    ),
    '#default_value' => $data['text']['align'],
    '#description' => t('Select how the text should be aligned within the resulting image. The default aligns to the left.'),
  );

  // Line spacing (Leading).
  $form['settings']['text']['line_spacing'] = array(
    '#type' => 'textfield',
    '#title' => t('Line spacing (Leading)'),
    '#field_suffix' => t('px'),
    '#default_value' => $data['text']['line_spacing'],
    '#maxlength' => 4,
    '#size' => 4,
    '#element_validate' => array(
      'element_validate_integer',
    ),
    '#description' => t('Specify the space in pixels to be added between text lines (Leading).'),
  );
  $form['settings']['text']['case_format'] = array(
    '#type' => 'select',
    '#title' => t('Case format'),
    '#options' => array(
      '' => t('Default'),
      'upper' => t('UPPERCASE'),
      'lower' => t('lowercase'),
      'ucwords' => t('Uppercase Words'),
      'ucfirst' => t('Uppercase first'),
    ),
    '#description' => t('Convert the input text to a desired format. The default makes no changes to input text.'),
    '#default_value' => $data['text']['case_format'],
  );

  // ---- Layout settings.
  $form['settings']['layout'] = array(
    '#type' => 'fieldset',
    '#title' => t('Layout settings'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );

  // Position.
  $form['settings']['layout']['position'] = array(
    '#type' => 'fieldset',
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#title' => t('Position'),
  );
  $form['settings']['layout']['position']['placement'] = array(
    '#type' => 'radios',
    '#title' => t('Placement'),
    '#options' => array(
      'left-top' => t('Top') . ' ' . t('Left'),
      'center-top' => t('Top') . ' ' . t('Center'),
      'right-top' => t('Top') . ' ' . t('Right'),
      'left-center' => t('Center') . ' ' . t('Left'),
      'center-center' => t('Center'),
      'right-center' => t('Center') . ' ' . t('Right'),
      'left-bottom' => t('Bottom') . ' ' . t('Left'),
      'center-bottom' => t('Bottom') . ' ' . t('Center'),
      'right-bottom' => t('Bottom') . ' ' . t('Right'),
    ),
    '#theme' => 'image_anchor',
    '#default_value' => implode('-', array(
      $data['layout']['x_pos'],
      $data['layout']['y_pos'],
    )),
    '#description' => t('Position of the text on the underlying image.'),
  );
  $form['settings']['layout']['position']['x_offset'] = array(
    '#type' => 'textfield',
    '#title' => t('Horizontal offset'),
    '#field_suffix' => 'px',
    '#description' => t('Additional horizontal offset from placement.'),
    '#default_value' => $data['layout']['x_offset'],
    '#maxlength' => 4,
    '#size' => 4,
    '#element_validate' => array(
      'element_validate_integer',
    ),
  );
  $form['settings']['layout']['position']['y_offset'] = array(
    '#type' => 'textfield',
    '#title' => t('Vertical offset'),
    '#field_suffix' => 'px',
    '#description' => t('Additional vertical offset from placement.'),
    '#default_value' => $data['layout']['y_offset'],
    '#maxlength' => 4,
    '#size' => 4,
    '#element_validate' => array(
      'element_validate_integer',
    ),
  );

  // Overflow action.
  $form['settings']['layout']['position']['overflow_action'] = array(
    '#type' => 'radios',
    '#title' => t('Overflow'),
    '#default_value' => $data['layout']['overflow_action'],
    '#options' => array(
      'extend' => t('<b>Extend image.</b> The underlying image will be extended to fit the text.'),
      'crop' => t('<b>Crop text.</b> Only the part of the text fitting in the image is rendered.'),
      'scaletext' => t('<b>Scale text.</b> The text will be scaled to fit the underlying image.'),
    ),
    '#description' => t('Action to take if text overflows the underlying image.'),
  );

  // Padding.
  $form['settings']['layout']['padding'] = array(
    '#type' => 'fieldset',
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#title' => t('Padding'),
    '#description' => t('Specify the padding in pixels to be added around the generated text.'),
  );
  $form['settings']['layout']['padding']['top'] = array(
    '#type' => 'textfield',
    '#title' => t('Top'),
    '#field_suffix' => t('px'),
    '#default_value' => $data['layout']['padding_top'],
    '#maxlength' => 4,
    '#size' => 4,
    '#element_validate' => array(
      'element_validate_integer',
    ),
  );
  $form['settings']['layout']['padding']['right'] = array(
    '#type' => 'textfield',
    '#title' => t('Right'),
    '#field_suffix' => t('px'),
    '#default_value' => $data['layout']['padding_right'],
    '#maxlength' => 4,
    '#size' => 4,
    '#element_validate' => array(
      'element_validate_integer',
    ),
  );
  $form['settings']['layout']['padding']['bottom'] = array(
    '#type' => 'textfield',
    '#title' => t('Bottom'),
    '#field_suffix' => t('px'),
    '#default_value' => $data['layout']['padding_bottom'],
    '#maxlength' => 4,
    '#size' => 4,
    '#element_validate' => array(
      'element_validate_integer',
    ),
  );
  $form['settings']['layout']['padding']['left'] = array(
    '#type' => 'textfield',
    '#title' => t('Left'),
    '#field_suffix' => t('px'),
    '#default_value' => $data['layout']['padding_left'],
    '#maxlength' => 4,
    '#size' => 4,
    '#element_validate' => array(
      'element_validate_integer',
    ),
  );

  // Background color.
  $form['settings']['layout']['background_color'] = array(
    '#type' => 'textimage_color',
    '#title' => t('Background color'),
    '#description' => t('Select the color you wish to use for the background of the text.'),
    '#allow_transparent' => TRUE,
    '#allow_opacity' => TRUE,
    '#default_value' => $data['layout']['background_color'],
  );
  $form['#attached']['css'] = array(
    drupal_get_path('module', 'textimage') . '/misc/css/textimage.admin.css',
  );
  $form['#element_validate'][] = 'textimage_text_effect_form_validate';
  return $form;
}