You are here

function rrssb_form in Ridiculously Responsive Social Sharing Buttons 7

Same name and namespace in other branches
  1. 7.2 rrssb.module \rrssb_form()

Implements hook_form().

1 string reference to 'rrssb_form'
rrssb_menu in ./rrssb.module
Implements hook_menu().

File

./rrssb.module, line 209

Code

function rrssb_form() {
  $all_buttons = rrssb_settings(TRUE);
  $chosen = rrssb_get_chosen();
  $form['rrssb_follow'] = array(
    '#type' => 'select',
    '#title' => t('Select type of buttons'),
    '#options' => array(
      0 => t('Share'),
      1 => t('Follow'),
    ),
    '#default_value' => variable_get('rrssb_follow'),
    '#description' => t('"Share" buttons invite the visitor to share the page from your site onto their page/channel/profile.  "Follow" buttons direct the visitor to your page/channel/profile.'),
  );

  // Create the config for the table of buttons.
  // Drupal handles all the storing to the rrssb_chosen variable automatically, serialising the array.
  // The table layout comes from the theme function.
  $form['rrssb_chosen'] = array(
    '#type' => 'fieldset',
    '#tree' => TRUE,
    '#title' => t('Configure buttons'),
    '#theme' => 'rrssb_config_buttons',
  );
  foreach ($all_buttons as $name => $button) {

    // Determine if this button requires a particular value of rrssb_follow to be valid.
    // This is the case if one or other of the URL as not present.
    // Both URLs absent makes no sense and would be a bug.
    unset($require_follow);
    if (!isset($button['follow_url'])) {
      $require_follow = 0;
    }
    else {
      if (!isset($button['share_url'])) {
        $require_follow = 1;
      }
    }
    $form['rrssb_chosen'][$name]['label'] = array(
      '#type' => 'item',
      '#markup' => $button['text'],
    );
    $form['rrssb_chosen'][$name]['enabled'] = array(
      '#type' => 'checkbox',
      '#default_value' => isset($chosen[$name]['enabled']) ? $chosen[$name]['enabled'] : FALSE,
    );
    if (isset($require_follow)) {

      // Hide entries where there is no corresponding URL.
      $form['rrssb_chosen'][$name]['enabled']['#states'] = array(
        'visible' => array(
          ":input[name='rrssb_follow']" => array(
            'value' => $require_follow,
          ),
        ),
      );
    }
    if (isset($button['follow_url'])) {
      $form['rrssb_chosen'][$name]['username'] = array(
        '#type' => 'textfield',
        '#default_value' => isset($chosen[$name]['username']) ? $chosen[$name]['username'] : '',
        // Hide the username for share URLs where it isn't needed.  Otherwise it is a required field.
        // @@TODO Required field not working.
        '#states' => array(
          'visible' => array(
            ":input[name='rrssb_follow']" => array(
              'value' => 1,
            ),
          ),
          'required' => array(
            ":input[name='rrssb_chosen[{$name}][enabled]']" => array(
              'checked' => TRUE,
            ),
          ),
        ),
      );
    }
    $form['rrssb_chosen'][$name]['weight'] = array(
      '#type' => 'weight',
      '#default_value' => isset($chosen[$name]['weight']) ? $chosen[$name]['weight'] : 0,
      '#delta' => 20,
      '#attributes' => array(
        'class' => array(
          'item-row-weight',
        ),
      ),
    );
  }
  $form['rrssb_prefix'] = array(
    '#type' => 'textfield',
    '#title' => t('Prefix text before the buttons'),
    '#default_value' => variable_get('rrssb_prefix'),
    '#description' => t('Put this text before the buttons.  For example "Follow us" or "Share this page".'),
  );
  $form['rrssb_image_tokens'] = array(
    '#type' => 'textfield',
    '#title' => t('Tokens to use to find images'),
    '#default_value' => variable_get('rrssb_image_tokens', RRSSB_IMAGE_TOKENS_DEFAULT),
    '#description' => t('Enter one or more tokens, separated by |.  These tokens will be tried in turn to determine the image to use in buttons.
      The default value is !default which you can adapt to pick other fields or as desired.', array(
      '!default' => RRSSB_IMAGE_TOKENS_DEFAULT,
    )),
  );
  $form['#submit'][] = 'rrssb_form_submit';
  $form['#validate'][] = 'rrssb_form_validate';
  return system_settings_form($form);
}