You are here

function sharebar_addbutton in ShareBar 7

Same name and namespace in other branches
  1. 6 sharebar.admin.inc \sharebar_addbutton()
  2. 7.2 sharebar.admin.inc \sharebar_addbutton()

Form builder: create buttons.

1 string reference to 'sharebar_addbutton'
sharebar_menu in ./sharebar.module
Implements hook_menu().

File

./sharebar.admin.inc, line 53
Admin page callbacks for the block module.

Code

function sharebar_addbutton($form, &$form_state, $edit = array()) {
  $mname = arg(4);
  $button = new stdClass();
  $button->name = $button->machine_name = $button->big_button = $button->small_button = $button->enabled = $button->weight = '';
  if ($mname) {
    $buttons = unserialize(variable_get('sharebar_buttons', sharebar_buttons_def()));
    if (is_array($buttons) && count($buttons)) {
      $button = $buttons[$mname];
    }
  }
  $form['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Name'),
    '#default_value' => $button->name,
    '#maxlength' => 255,
    '#required' => TRUE,
  );
  $form['machine_name'] = array(
    '#type' => 'machine_name',
    '#default_value' => $button->machine_name,
    '#maxlength' => 21,
    '#machine_name' => array(
      'exists' => 'sharebar_machine_name_load',
    ),
  );
  $form['old_machine_name'] = array(
    '#type' => 'value',
    '#value' => $button->machine_name,
  );
  $form['big_button'] = array(
    '#type' => 'textarea',
    '#title' => t('Big Button'),
    '#default_value' => $button->big_button,
    '#required' => TRUE,
  );
  $form['small_button'] = array(
    '#type' => 'textarea',
    '#title' => t('Small Button'),
    '#default_value' => $button->small_button,
    '#required' => TRUE,
  );

  // Display placeholders.
  if (module_exists('token')) {
    $form['token_help'] = array(
      '#title' => t('Replacement patterns'),
      '#type' => 'fieldset',
      '#description' => t('Be very careful while using node specific tokens,
        as these are available only for nodes, so you might see naked token on
        non-nodes and can be a reason for breakage:'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
    );
    $form['token_help']['token_tree'] = array(
      '#theme' => 'token_tree',
      '#token_types' => array(
        'node',
      ),
      '#show_restricted' => TRUE,
      '#dialog' => TRUE,
      '#description' => t('x'),
    );
  }
  $form['enabled'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enabled'),
    '#default_value' => $button->enabled,
  );
  $form['weight'] = array(
    '#type' => 'weight',
    '#title' => t('Weight'),
    '#delta' => 50,
    '#default_value' => $button->weight,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  return $form;
}