You are here

function sharerich_ctools_export_ui_form in Sharerich 7.3

Same name and namespace in other branches
  1. 7.2 plugins/export_ui/sharerich_ctools_export_ui.inc \sharerich_ctools_export_ui_form()

Define the preset add/edit form.

1 string reference to 'sharerich_ctools_export_ui_form'
sharerich_ctools_export_ui.inc in plugins/export_ui/sharerich_ctools_export_ui.inc

File

plugins/export_ui/sharerich_ctools_export_ui.inc, line 35

Code

function sharerich_ctools_export_ui_form(&$form, &$form_state) {
  $item = $form_state['op'] == 'add' ? $form_state['item'] : $form_state['item']->raw;

  // Generate the list of available services.
  $services = sharerich_get_services();
  $form['settings'] = array(
    '#type' => 'vertical_tabs',
  );
  $form['general'] = array(
    '#type' => 'fieldset',
    '#title' => t('General settings'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#group' => 'settings',
  );
  $form['available_services'] = array(
    '#type' => 'fieldset',
    '#title' => t('Services'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#group' => 'settings',
  );
  $form['custom_markup'] = array(
    '#type' => 'fieldset',
    '#title' => t('Custom Markup'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#group' => 'settings',
    '#description' => '<strong>' . t('In order to edit the markup, you need to enable the services in the "Services tab".') . '</strong>',
  );

  // Use our dragable table theme function.
  $form['available_services']['services'] = array(
    '#theme' => 'sharerich_manage_services',
    '#tree' => TRUE,
  );
  foreach ($services as $service_name) {
    $form['available_services']['services'][$service_name]['service'] = array(
      '#markup' => $service_name,
    );
    $form['available_services']['services'][$service_name]['enabled'] = array(
      '#type' => 'checkbox',
      '#default_value' => isset($item->services[$service_name]['enabled']) ? $item->services[$service_name]['enabled'] : 0,
    );

    // Store the buttons markup along other data.
    $form['available_services']['services'][$service_name]['markup'] = array(
      '#type' => 'hidden',
      '#value' => sharerich_get_service_content($service_name, $item->machinename),
    );

    // The field contains sort info (weights).
    $form['available_services']['services'][$service_name]['weight'] = array(
      '#type' => 'weight',
      '#title' => t('Weight'),
      '#title_display' => 'invisible',
      '#default_value' => isset($item->services[$service_name]['weight']) ? $item->services[$service_name]['weight'] : 0,
    );
  }

  // Sort the services.
  uasort($form['available_services']['services'], 'drupal_sort_weight');
  $form['general']['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Set name'),
    '#required' => TRUE,
    '#maxlength' => 64,
    '#default_value' => $item->name,
    '#description' => t('Example: Article Top'),
    '#weight' => -2,
  );
  $form['general']['machinename'] = array(
    '#type' => 'machine_name',
    '#title' => t('Machine name'),
    '#maxlength' => 64,
    '#default_value' => $item->machinename,
    '#description' => t('Only use letters, numbers and underscores. Example: article_top'),
    '#machine_name' => array(
      'exists' => 'sharerich_set_name_exists',
      'source' => array(
        'general',
        'name',
      ),
    ),
    '#weight' => -1,
  ) + $form['info']['machinename'];
  unset($form['info']);
  $form['general']['block'] = array(
    '#type' => 'checkbox',
    '#title' => t('Create a block for this button set.'),
    '#description' => '',
    '#default_value' => $item->block,
  );
  $form['general']['title'] = array(
    '#type' => 'textfield',
    '#title' => t('Title'),
    '#description' => t('This is the title that appears above the share buttons.'),
    '#default_value' => !empty($item->title) ? $item->title : '',
    '#states' => array(
      'visible' => array(
        ':input[name="block"]' => array(
          'checked' => TRUE,
        ),
      ),
    ),
  );

  // Custom widgets.
  foreach ($services as $service_name) {
    $var_name = 'sharerich_custom_' . $service_name;
    $form['custom_markup'][$var_name] = array(
      '#type' => 'textarea',
      '#title' => t('Custom code for %name', array(
        '%name' => $service_name,
      )),
      '#description' => '',
      '#default_value' => sharerich_get_service_content($service_name, $item->machinename),
      '#states' => array(
        'invisible' => array(
          ':input[name="services[' . $service_name . '][enabled]"]' => array(
            'checked' => FALSE,
          ),
        ),
      ),
    );
  }
}