You are here

function sharemessage_form in Share Message 7

Share message form.

File

./sharemessage.module, line 236
New Sharing Module.

Code

function sharemessage_form($form, &$form_state, $sharemessage) {
  global $language;
  $form_state['sharemessage'] = $sharemessage;
  $smid = entity_id('sharemessage', $sharemessage);
  $form['label'] = array(
    '#type' => 'textfield',
    '#title' => t('Label'),
    '#required' => TRUE,
    '#default_value' => isset($sharemessage->label) ? $sharemessage->label : '',
    '#weight' => -3,
  );
  if (empty($smid)) {
    $form['name'] = array(
      '#type' => 'machine_name',
      '#title' => t('Machine Name'),
      '#machine_name' => array(
        'exists' => 'sharemessage_check_machine_name_if_exist',
        'source' => array(
          'label',
        ),
      ),
      '#required' => TRUE,
      '#weight' => -2,
    );
  }
  field_attach_form('sharemessage', $sharemessage, $form, $form_state, $language->language);

  // Settings fieldset.
  $form['override_default_settings'] = array(
    '#type' => 'checkbox',
    '#title' => t('Override default settings'),
    '#default_value' => isset($sharemessage->override_default_settings) ? $sharemessage->override_default_settings : FALSE,
    '#weight' => 101,
  );
  $form['settings'] = array(
    '#type' => 'fieldset',
    '#title' => t('Customized settings'),
    '#tree' => TRUE,
    '#weight' => 102,
    '#states' => array(
      'invisible' => array(
        ':input[name="override_default_settings"]' => array(
          'checked' => FALSE,
        ),
      ),
    ),
  );
  if (module_exists('shariff')) {
    $form['settings']['type'] = [
      '#type' => 'radios',
      '#title' => t('Type'),
      '#options' => array(
        'addthis' => 'Addthis',
        'shariff' => 'Shariff',
      ),
      '#default_value' => isset($sharemessage->settings['type']) ? $sharemessage->settings['type'] : variable_get('sharemessage_default_type', 'addthis'),
    ];
  }
  $form['settings']['icon_style'] = array(
    '#type' => 'radios',
    '#title' => t('Icon style'),
    '#options' => sharemessage_get_sharewidget_options(),
    '#default_value' => isset($sharemessage->settings['icon_style']) ? $sharemessage->settings['icon_style'] : variable_get('sharemessage_default_icon_style', 'addthis_16x16_style'),
    '#description' => t('For the vertical floated items with counters, the only available services are Facebook Like, Google+ Share and Tweet. The addthis counter will also get added automatically when enabling additional services button.'),
  );
  $form['settings']['services'] = array(
    '#type' => 'select',
    '#title' => t('Visible services'),
    '#multiple' => TRUE,
    '#options' => sharemessage_get_addthis_services(),
    '#default_value' => !empty($sharemessage->settings['services']) ? $sharemessage->settings['services'] : variable_get('sharemessage_default_services', array()),
    '#size' => 10,
    '#states' => array(
      'invisible' => array(
        ':input[name="settings[icon_style]"]' => array(
          'value' => 'addthis_counter_style',
        ),
      ),
    ),
  );
  $form['settings']['additional_services'] = array(
    '#type' => 'checkbox',
    '#title' => t('Show additional services button'),
    '#default_value' => isset($sharemessage->settings['additional_services']) ? $sharemessage->settings['additional_services'] : variable_get('sharemessage_default_additional_services', TRUE),
  );
  $form['settings']['counter'] = array(
    '#type' => 'select',
    '#title' => t('Show Addthis counter'),
    '#empty_option' => t('No'),
    '#options' => array(
      'addthis_pill_style' => t('Pill style'),
      'addthis_bubble_style' => t('Bubble style'),
    ),
    '#default_value' => isset($sharemessage->settings['counter']) ? $sharemessage->settings['counter'] : variable_get('sharemessage_default_counter', FALSE),
    '#states' => array(
      'invisible' => array(
        ':input[name="settings[icon_style]"]' => array(
          'value' => 'addthis_counter_style',
        ),
      ),
    ),
  );
  $form['block'] = array(
    '#type' => 'checkbox',
    '#title' => t('Provide a block'),
    '#default_value' => isset($sharemessage->block) ? $sharemessage->block : 0,
    '#weight' => 103,
  );
  if (variable_get('sharemessage_message_enforcement', TRUE)) {
    $form['enforce_usage'] = array(
      '#type' => 'checkbox',
      '#title' => t('Enforce the usage of this share message on the page it points to'),
      '#description' => t('If checked, this sharemessage will be used on the page that it is referring to and override the sharemessage there.'),
      '#default_value' => isset($sharemessage->settings['enforce_usage']) ? $sharemessage->settings['enforce_usage'] : 0,
      '#weight' => 105,
    );
  }
  if (module_exists('token')) {
    $form['sharemessage_token_help'] = array(
      '#title' => t('Replacement patterns'),
      '#type' => 'fieldset',
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
      '#description' => t('These tokens can be used in all text fields.'),
      '#weight' => 104,
    );
    $form['sharemessage_token_help']['browser'] = array(
      '#theme' => 'token_tree',
      '#token_types' => array(
        'node',
        'sharemessage',
      ),
      '#dialog' => TRUE,
    );
  }
  $submit = array();
  if (!empty($form['#submit'])) {
    $submit += $form['#submit'];
  }
  $form['actions'] = array(
    '#weight' => 106,
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save share message'),
    '#submit' => $submit + array(
      'sharemessage_form_submit',
    ),
  );
  return $form;
}