You are here

function mostpopular_services_admin_form in Drupal Most Popular 7

Renders a form for configuring the blocks and services.

1 string reference to 'mostpopular_services_admin_form'
mostpopular_menu in ./mostpopular.module
Implements hook_menu().

File

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

Code

function mostpopular_services_admin_form($form, &$form_state) {
  $form += array(
    '#tree' => TRUE,
    'blocks' => array(
      '#theme' => 'mostpopular_admin_services_table',
    ),
  );
  $blocks = mostpopular_blocks_local();
  $form_state['blocks'] = $blocks;
  $block_options = array();
  foreach ($blocks as $bid => $block) {
    $block_options[$bid] = $block->title;
  }
  foreach ($blocks as $bid => $block) {
    $form['blocks'][$bid] = array(
      '#type' => 'fieldset',
      '#title' => t('Block: @title', array(
        '@title' => $block->title,
      )),
      'bid' => array(
        '#type' => 'hidden',
        '#value' => $bid,
      ),
      'services' => array(
        '#tree' => TRUE,
      ),
    );
    $services = mostpopular_service_load_by_block($bid, FALSE);
    $form_state['services'][$bid] = $services;
    foreach ($services as $sid => $service) {
      $form['blocks'][$bid]['services'][$sid] = array(
        'id' => array(
          '#markup' => !empty($service->sid) ? $service->sid : t('New'),
        ),
        'name' => array(
          '#markup' => check_plain($service->name),
        ),
        'enabled' => array(
          '#type' => 'checkbox',
          '#default_value' => $service->enabled,
        ),
        'status' => array(
          '#theme' => 'mostpopular_service_status',
          '#status' => $service->status,
        ),
        'title' => array(
          '#type' => 'textfield',
          '#size' => 32,
          '#default_value' => check_plain($service->title),
        ),
        'weight' => array(
          '#type' => 'textfield',
          '#size' => 3,
          '#default_value' => $service->weight,
        ),
        'bid' => array(
          '#type' => 'select',
          '#default_value' => $bid,
          '#options' => $block_options,
        ),
        'config' => array(
          'configure' => array(
            '#type' => 'link',
            '#title' => t('Configure'),
            '#href' => "admin/config/mostpopular/services/{$sid}/edit",
            '#suffix' => '  ',
          ),
          'delete' => array(
            '#type' => 'link',
            '#title' => t('Delete'),
            '#href' => "admin/config/mostpopular/services/{$sid}/delete",
          ),
        ),
      );
    }
  }

  // Add a section for adding a new service
  $info = mostpopular_service_info();
  $options = array();
  foreach ($info as $module => $inf) {
    foreach ($inf as $delta => $in) {
      $options[$module]["{$module}|{$delta}"] = $in['name'];
    }
  }
  if (count($blocks) > 0) {
    $form['add_service'] = array(
      '#tree' => TRUE,
      '#type' => 'container',
      '#attributes' => array(),
      'service' => array(
        '#type' => 'select',
        '#multiple' => FALSE,
        '#options' => $options,
      ),
      'button' => array(
        '#type' => 'submit',
        '#value' => t('Add Service'),
        '#submit' => array(
          'mostpopular_services_admin_form_add_service',
        ),
      ),
    );
  }
  $form['save'] = array(
    '#type' => 'submit',
    '#value' => t('Save Configuration'),
    '#submit' => array(
      'mostpopular_services_admin_form_submit',
    ),
  );
  return $form;
}