You are here

function configuration_tracking_form in Configuration Management 7

Menu Callback Form.

1 string reference to 'configuration_tracking_form'
configuration_menu in ./configuration.module
Implements hook_menu().

File

./configuration.admin.inc, line 6

Code

function configuration_tracking_form($form, &$form_state) {
  module_load_include('inc', 'configuration', 'configuration.export');
  configuration_include();
  $config = configuration_get_configuration();

  // Use multi-step forms to be able to stop tracking configurations
  // using a confirmation form.
  if (!empty($form_state['page_num']) && $form_state['page_num'] == 2) {
    return configuration_confirm_delete_multiple($form, $form_state);
  }
  $form_state['page_num'] = 1;

  // Unset the status variable that is in the config cache
  // @todo: Thinkin about moving this state out of the config cache array.
  unset($config['overridden']);
  if (empty($config)) {
    $form['no_configs'] = array(
      '#markup' => t('No Configurations were found. Please use the
      !export_link page to begin tracking new Configurations.', array(
        '!export_link' => l(t('Not Tracking'), 'admin/config/system/configuration/notracking'),
      )),
    );
    return $form;
  }
  $form['help_text'] = array(
    '#markup' => 'Choose the configurations to write or activate.  Writing to activestore requires writing the entire component to datastore. You cannot write individual configs to datastore.  You have to select all components and write the entire component to datastore. Individual components may be imported into activestore.',
    '#prefix' => '<div>',
    '#suffix' => '</div>',
  );
  $form['packages'] = array(
    '#type' => 'vertical_tabs',
  );
  $form['#attached']['css'] = array(
    drupal_get_path('module', 'configuration') . '/theme/configuration.css',
  );
  $components = configuration_get_components();
  ksort($components);
  $js_settings = array();
  $component_exists = FALSE;
  foreach ($components as $component => $component_info) {
    $overridden = '';
    if (array_key_exists($component, $config)) {
      $component_exists = TRUE;
      $form[$component] = array(
        '#type' => 'fieldset',
        '#group' => 'packages',
        '#title' => check_plain($component_info['name']),
        '#description' => t('Configurations you are currently tracking in %config_type.', array(
          '%config_type' => $component_info['name'],
        )),
        '#collapsible' => TRUE,
        '#collapsed' => TRUE,
        '#tree' => TRUE,
        '#attached' => array(
          'js' => array(
            'vertical-tabs' => drupal_get_path('module', 'configuration') . '/theme/vertical-tabs.js',
          ),
        ),
      );

      // Show checkboxes for out of sync configurations
      $items = $overridden_items = $delete_items = array();
      $checkbox = array();
      $header = array(
        'name' => t('Configuration Name'),
        'status' => t('Status'),
        'action' => t('Action'),
      );
      foreach ($config[$component] as $config_item => $fields) {
        $status = _configuration_get_status_link($fields['status'], $component, $config_item);
        $action = l(t('Stop tracking'), 'admin/config/system/configuration/config/' . $component . '/' . $config_item . '/delete');
        $class = '';

        // Dependents should have a css class and no Stop Tracking link
        if ($fields['parent']) {
          $action = t('Dependent Configuration');
          $class = 'config-dependent';
        }
        if ($fields['status'] & (CONFIGURATION_ACTIVESTORE_OVERRIDDEN | CONFIGURATION_DATASTORE_OVERRIDDEN | CONFIGURATION_DATASTORE_ONLY | CONFIGURATION_TRACKED_DATASTORE_ONLY)) {
          $overridden = TRUE;
          $overridden_items[$config_item] = array(
            'name' => $config_item,
            'status' => $status,
            'action' => $action,
          );

          // $overridden_items[$config_item] = array('class' => array($class), 'data' => array('name' => $config_item, 'status' => t('Overridden'), 'action' => $action));
        }
        elseif ($fields['status'] == CONFIGURATION_IN_SYNC) {

          // $items[$config_item] = array('class' => array($class), 'data' => array('name' => $config_item, 'status' => t('Default'), 'action' => $action));
          $items[$config_item] = array(
            'name' => $config_item,
            'status' => $status,
            'action' => $action,
          );
        }
        elseif ($fields['status'] == CONFIGURATION_DELETE) {

          // $delete_items[$config_item] = array('class' => array('config-delete'), 'data' => array('name' => $config_item, 'status' => t('No Longer in Activestore'), 'action' => $action));
          $delete_items[$config_item] = array(
            'name' => $config_item,
            'status' => $status,
            'action' => $action,
          );
        }
      }
      $all_items = $items + $delete_items;
      $form[$component]['items'] = array(
        '#type' => 'tableselect',
        '#header' => $header,
        '#options' => $overridden_items + $all_items,
        '#attributes' => array(
          'id' => 'configuration-table-select-' . $component,
        ),
        '#overridden' => count($overridden_items),
      );
    }
    if ($overridden) {
      $form[$component]['#attributes']['class'] = array(
        'overridden',
      );
    }

    // Set variables in in js for setting the tab summaries
    $js_settings['configuration'][$component] = $component;
  }

  // If not tabs are shown, that means no configurations are being tracked.
  if (!$component_exists) {
    unset($form['help_text']);
    $form['no_configs'] = array(
      '#markup' => t('No Configurations were found. Please use the
      !export_link page to begin tracking new Configurations.', array(
        '!export_link' => l(t('Not Tracking'), 'admin/config/system/configuration/notracking'),
      )),
    );
    return $form;
  }
  drupal_add_js($js_settings, 'setting');
  $form['buttons'] = array(
    '#theme' => 'configuration_form_buttons',
    '#tree' => FALSE,
  );

  // Do not allow writing to datastore if on remote server.
  if (variable_get('remote_server', 0) < 1) {
    $form['buttons']['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Write Activestore to Datastore'),
      '#weight' => 9,
    );
  }
  $form['buttons']['stop_tracking'] = array(
    '#type' => 'submit',
    '#value' => t('Stop Tracking'),
    '#weight' => 20,
    '#submit' => array(
      'configuration_stop_tracking_form_submit',
    ),
  );
  $form['buttons']['revert'] = array(
    '#type' => 'submit',
    '#value' => t('Import Datastore to Activestore'),
    '#weight' => 10,
    '#submit' => array(
      'configuration_activate_form_submit',
    ),
  );

  // Hide the action buttons if there is nothing overridden
  if (!$component_exists) {
    unset($form['buttons']);
  }

  // Use the same handlers as the notracking form
  $form['#validate'][] = 'configuration_notracking_form_validate';
  $form['#validate'][] = 'configuration_tracking_form_validate';
  $form['#validate'][] = 'configuration_stop_tracking_form_validate';
  $form['#submit'][] = 'configuration_notracking_form_submit';
  return $form;
}