You are here

function configuration_activate_form in Configuration Management 7

Menu Callback Form.

File

./configuration.admin.inc, line 329

Code

function configuration_activate_form($form, &$form_state) {
  module_load_include('inc', 'configuration', 'configuration.export');
  configuration_include();
  $config = configuration_get_configuration();
  $form['packages'] = array(
    '#type' => 'vertical_tabs',
  );
  $form['#attached']['css'] = array(
    drupal_get_path('module', 'configuration') . '/theme/configuration.css',
  );
  $components = configuration_get_components();
  $empty_components = array();
  $show_form = FALSE;
  foreach ($components as $component => $component_info) {
    if (array_key_exists($component, $config)) {
      $empty_components[$component] = $component;
      $form[$component] = array(
        '#type' => 'fieldset',
        '#group' => 'packages',
        '#title' => check_plain($component_info['name']),
        '#description' => t('Configurations that need to be activated in %config_type.', array(
          '%config_type' => $component_info['name'],
        )),
        '#collapsible' => TRUE,
        '#collapsed' => TRUE,
        '#tree' => TRUE,
      );

      // Show checkboxes for out of sync configurations
      $items = $overridden_items = array();
      $checkbox = array();
      $header = array(
        'name' => t('Configuration Name'),
        'status' => t('Status'),
        'action' => t('Action'),
      );
      foreach ($config[$component] as $config_item => $fields) {
        if ($fields['status'] & (CONFIGURATION_DATASTORE_ONLY | CONFIGURATION_DATASTORE_OVERRIDDEN)) {
          $status = $fields['status'] == CONFIGURATION_DATASTORE_ONLY ? t('New Configuration') : l(t('Update Configuration'), 'admin/config/system/configuration/' . $component . '/' . $config_item . '/diff');
          $overridden_items[$config_item] = array(
            'name' => $config_item,
            'status' => $status,
            'action' => l(t('Stop tracking'), 'admin/config/system/configuration/config/' . $component . '/' . $config_item . '/delete'),
          );
          $empty_components[$component] = FALSE;
          $show_form = TRUE;
        }
      }
      if (!empty($overridden_items)) {
        $form[$component]['items'] = array(
          '#type' => 'tableselect',
          '#header' => $header,
          '#options' => $overridden_items,
          '#attributes' => array(
            'id' => 'configuration-table-select-' . $component,
          ),
        );
      }
    }
  }

  // Unset any components that do not need to be activated.
  $empty_components = array_filter($empty_components);
  foreach ($empty_components as $component) {
    unset($form[$component]);
  }
  if (!$show_form) {
    $form['no_configs'] = array(
      '#markup' => t('No new configurations were found to activate.'),
    );
    return $form;
  }
  $form['buttons'] = array(
    '#theme' => 'configuration_form_buttons',
    '#tree' => FALSE,
  );
  $form['buttons']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Activate in Activestore'),
    '#weight' => 9,
  );
  $form['buttons']['revert'] = array(
    '#type' => 'submit',
    '#value' => t('Update Datastore'),
    '#weight' => 10,
    '#submit' => array(
      'configuration_notracking_form_submit',
    ),
  );
  $form['#validate'][] = 'configuration_notracking_form_validate';
  $form['#submit'][] = 'configuration_activate_form_submit';
  return $form;
}