function rrssb_form in Ridiculously Responsive Social Sharing Buttons 7.2
Same name and namespace in other branches
- 7 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('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']) && strpos($button['follow_url'], '[rrssb:username]') !== FALSE) {
$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',
),
),
);
}
// Appearance settings stored as an array ready to pass to the library code.
$appearance = rrssb_appearance();
$form['rrssb_appearance'] = array(
'#type' => 'fieldset',
'#tree' => TRUE,
'#title' => t('Appearance'),
);
$form['rrssb_appearance']['size'] = array(
'#type' => 'textfield',
'#title' => t('Size'),
'#size' => 5,
'#default_value' => $appearance['size'],
'#description' => t('Size, as a proportion of default size set in CSS.'),
);
$form['rrssb_appearance']['shrink'] = array(
'#type' => 'textfield',
'#title' => t('Minimum size'),
'#size' => 5,
'#default_value' => $appearance['shrink'],
'#description' => t('Minimum size to shrink buttons to, as a proportion of original size.'),
);
$form['rrssb_appearance']['regrow'] = array(
'#type' => 'textfield',
'#title' => t('Extra row size'),
'#size' => 5,
'#default_value' => $appearance['regrow'],
'#description' => t('Maximum size of buttons after they have been forced to split onto extra rows of buttons, as a proportion of original size.'),
);
$form['rrssb_appearance']['minRows'] = array(
'#type' => 'textfield',
'#title' => t('Minimum rows'),
'#size' => 5,
'#default_value' => $appearance['minRows'],
'#description' => t('Minimum number of rows of buttons. Set to a large value to create vertical layout.'),
);
$form['rrssb_appearance']['maxRows'] = array(
'#type' => 'textfield',
'#title' => t('Maximum rows'),
'#size' => 5,
'#default_value' => $appearance['maxRows'],
'#description' => t('Maximum number of rows of buttons. If more rows would be needed, instead the labels are hidden. Set to a large value to keep labels if at all possible.'),
);
$form['rrssb_appearance']['prefixReserve'] = array(
'#type' => 'textfield',
'#title' => t('Prefix reserved width'),
'#size' => 5,
'#default_value' => $appearance['prefixReserve'],
'#description' => t('Proportion of total width reserved for prefix to be inline.'),
);
$form['rrssb_appearance']['prefixHide'] = array(
'#type' => 'textfield',
'#title' => t('Prefix maximum width'),
'#size' => 5,
'#default_value' => $appearance['prefixHide'],
'#description' => t('Maximum prefix width as a proportion of total width before hiding prefix.'),
);
$form['rrssb_appearance']['alignRight'] = array(
'#type' => 'checkbox',
'#title' => t('Right-align buttons'),
'#size' => 5,
'#default_value' => $appearance['alignRight'],
'#description' => t('By default, buttons are left-aligned, with any padding added on the right. Enable this to right-align, and instead pad on the left.'),
);
$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);
}