You are here

function button_field_field_widget_settings_form in Button Field 7

Implements hook_field_widget_settings_form().

File

./button_field.module, line 206
Defines a field, widget and formatter for the button field type.

Code

function button_field_field_widget_settings_form($field, $instance) {
  $widget = $instance['widget'];
  $form = array(
    'additional_classes' => array(
      '#type' => 'textfield',
      '#title' => t('Additional classes'),
      '#default_value' => $widget['settings']['additional_classes'],
      '#description' => t('Optionally, specify any classes to be applied to ' . 'the element. All button field elements will always have the ' . '"button_field" class. Seperate multiple classes with a space.'),
    ),
    'edit_hidden' => array(
      '#type' => 'checkbox',
      '#title' => t('Hide on edit form'),
      '#default_value' => $widget['settings']['edit_hidden'],
      '#description' => t('Whether or not this field will be rendered on ' . 'the node edit and add forms. Note: Nodes do not get assisgned a ' . 'node id on the add form; therefore, any Rules that require the ' . 'node to be available on button click will not function properly.'),
    ),
  );
  $widget_settings = array();
  switch ($instance['widget']['type']) {
    case 'button_field_html':
      $widget_settings['text'] = array(
        '#type' => 'textfield',
        '#title' => t('Button Text'),
        '#default_value' => !empty($widget['settings']['text']) ? $widget['settings']['text'] : $instance['label'],
        '#required' => TRUE,
      );
      break;
    case 'button_field_image':
      $widget_settings['image_path'] = array(
        '#type' => 'textfield',
        '#title' => t('Image path'),
        '#default_value' => $widget['settings']['image_path'],
        '#required' => TRUE,
      );
      $widget_settings['alt_text'] = array(
        '#type' => 'textfield',
        '#title' => t('Alt text'),
        '#default_value' => !empty($widget['settings']['alt_text']) ? $widget['settings']['alt_text'] : $instance['label'],
        '#required' => TRUE,
      );
      $widget_settings['title_text'] = array(
        '#type' => 'textfield',
        '#title' => t('Title text'),
        '#default_value' => !empty($widget['settings']['title_text']) ? $widget['settings']['title_text'] : $instance['label'],
        '#required' => FALSE,
      );
      break;
  }
  return array_merge($widget_settings, $form);
}