You are here

function mostpopular_service_config_form in Drupal Most Popular 7

Same name and namespace in other branches
  1. 6 mostpopular.admin.inc \mostpopular_service_config_form()
1 string reference to 'mostpopular_service_config_form'
mostpopular_menu in ./mostpopular.module
Implements hook_menu().

File

./mostpopular.services.inc, line 319
Provides an admin GUI for configuring services.

Code

function mostpopular_service_config_form($form, &$form_state, $sid) {
  $service = mostpopular_service_load($sid);
  $form_state['service'] = $service;
  $form['data'] = array(
    '#tree' => TRUE,
  );

  // If the service provides any configuration form, show it first
  $extra = _mostpopular_invoke('config_form', $service, $form_state);
  if ($extra) {
    $form['data'] += $extra;
  }
  if (isset($service->entity_types)) {
    $service->data += array(
      'entities_only' => FALSE,
      'entity_types' => array(),
    );
    $form['data']['entities_only'] = array(
      '#type' => 'checkbox',
      '#title' => t('Only include entities?'),
      '#description' => t('If checked, only entities will be included in the Most Popular results for this service.  Otherwise, any valid URL could be included.'),
      '#default_value' => $service->data['entities_only'],
      '#weight' => 49,
    );
    $form['data']['entity_types'] = array(
      '#type' => 'fieldset',
      '#collapsible' => TRUE,
      '#collapsed' => FALSE,
      '#title' => t('Entity Types'),
      '#tree' => TRUE,
      '#element_validate' => array(
        'mostpopular_service_config_form_validate_entity_types',
      ),
      '#states' => array(
        'invisible' => array(
          'input[name="data[entities_only]"]' => array(
            'checked' => FALSE,
          ),
        ),
      ),
      '#weight' => 50,
    );
    if ($service->entity_types === TRUE) {
      $entity_types = entity_get_info();
    }
    else {
      foreach ($service->entity_types as $name) {
        $entity_types[$name] = entity_get_info($name);
      }
    }
    foreach ($entity_types as $name => $info) {
      $service->data['entity_types'] += array(
        $name => array(),
      );

      // Only get entities with valid URIs
      if (!isset($info['uri callback']) && !isset($info['view callback'])) {
        continue;
      }
      $form['data']['entity_types'][$name] = array(
        '#type' => 'tableselect',
        '#multiple' => TRUE,
        '#header' => array(
          'title' => $info['label'],
        ),
        '#options' => array(),
        '#default_value' => $service->data['entity_types'][$name],
      );
      foreach ($info['bundles'] as $bundle => $data) {
        $form['data']['entity_types'][$name]['#options'][$bundle] = array(
          'title' => $data['label'],
        );
      }
    }
  }
  $form['actions'] = array(
    '#type' => 'actions',
    '#weight' => 100,
    'submit' => array(
      '#type' => 'submit',
      '#value' => 'Save configuration',
      '#submit' => array(
        'mostpopular_service_config_form_submit',
      ),
      '#weight' => 0,
    ),
    'back' => array(
      '#type' => 'link',
      '#title' => t('Back'),
      '#href' => 'admin/config/mostpopular/services',
      '#weight' => 30,
    ),
  );
  $form['#attached']['css'][] = drupal_get_path('module', 'mostpopular') . '/css/mostpopular-admin.css';
  drupal_set_title(mostpopular_service_title($sid), PASS_THROUGH);
  return $form;
}