You are here

function features_admin_components in Features 7.2

Same name and namespace in other branches
  1. 6 features.admin.inc \features_admin_components()
  2. 7 features.admin.inc \features_admin_components()

Form builder for 'admin/structure/features/%feature'.

The form shows an overview of components in the feature.

Parameters

array $form: Form array, as passed in from form API.

array $form_state: Form state.

\stdClass $feature: Feature module info object.

Return value

array Form array.

Throws

\Exception Exception that may theoretically be thrown in theme().

1 string reference to 'features_admin_components'
features_menu in ./features.module
Implements hook_menu().

File

./features.admin.inc, line 1307
Forms for Features admin screens.

Code

function features_admin_components($form, $form_state, $feature) {

  // Breadcrumb navigation.
  $breadcrumb[] = l(t('Home'), NULL);
  $breadcrumb[] = l(t('Administration'), 'admin');
  $breadcrumb[] = l(t('Structure'), 'admin/structure');
  $breadcrumb[] = l(t('Features'), 'admin/structure/features');
  drupal_set_breadcrumb($breadcrumb);
  module_load_include('inc', 'features', 'features.export');
  $form['#feature'] = $feature;

  // Store feature info for theme layer.
  $form['module'] = array(
    '#type' => 'value',
    '#value' => $feature->name,
  );
  $form['#info'] = $feature->info;
  $form['#dependencies'] = array();
  if (!empty($feature->info['dependencies'])) {
    foreach ($feature->info['dependencies'] as $dependency) {
      $parsed_dependency = drupal_parse_dependency($dependency);
      $dependency = $parsed_dependency['name'];
      $status = features_get_module_status($dependency);
      $form['#dependencies'][$dependency] = $status;
    }
  }
  $conflicts = features_get_conflicts();
  if (!module_exists($form['module']['#value']) && isset($form['module']['#value']) && !empty($conflicts[$form['module']['#value']])) {
    $module_conflicts = $conflicts[$form['module']['#value']];
    $conflicts = array();
    foreach ($module_conflicts as $conflict) {
      $conflicts = array_merge_recursive($conflict, $conflicts);
    }
  }
  else {
    $conflicts = array();
  }
  $form['#conflicts'] = $conflicts;
  $review = $revert = FALSE;

  // Iterate over components and retrieve status for display.
  $states = features_get_component_states(array(
    $feature->name,
  ), FALSE);
  $form['revert']['#tree'] = TRUE;
  foreach ($feature->info['features'] as $component => $items) {
    if (user_access('administer features') && array_key_exists($component, $states[$feature->name]) && in_array($states[$feature->name][$component], array(
      FEATURES_OVERRIDDEN,
      FEATURES_NEEDS_REVIEW,
    ))) {
      switch ($states[$feature->name][$component]) {
        case FEATURES_OVERRIDDEN:
          $revert = TRUE;
          break;
        case FEATURES_NEEDS_REVIEW:
          $review = TRUE;
          break;
      }
      $form['revert'][$component] = array(
        '#type' => 'checkbox',
        '#default_value' => FALSE,
      );
    }
    if (module_exists('diff')) {
      $diffpath = "admin/structure/features/{$feature->name}/diff/{$component}";
      $item = menu_get_item($diffpath);
      $path = $item && $item['access'] ? $diffpath : NULL;
    }
    else {
      $path = NULL;
    }
    $storage = FEATURES_DEFAULT;
    if (array_key_exists($component, $states[$feature->name])) {
      $storage = $states[$feature->name][$component];
    }
    elseif (array_key_exists($component, $conflicts)) {
      $storage = FEATURES_CONFLICT;
    }

    // This can be removed if the css is fixed so link doesn't move when
    // ajaxing and linke moved.
    $lock_link = '<span class="features-lock-empty"></span>';
    if (user_access('administer features') && (features_hook($component, 'features_revert') || features_hook($component, 'features_rebuild'))) {
      $lock_link = ' ' . theme('features_lock_link', array(
        'feature' => $feature->name,
        'component' => $component,
      ));
    }
    $form['components'][$component] = array(
      '#markup' => $lock_link . theme('features_storage_link', array(
        'storage' => $storage,
        'path' => $path,
      )),
    );
  }
  if ($review || $revert) {
    $form['buttons'] = array(
      '#theme' => 'features_form_buttons',
      '#tree' => TRUE,
    );
    if ($revert || $review) {
      $form['buttons']['revert'] = array(
        '#type' => 'submit',
        '#value' => t('Revert components'),
        /* @see \features_admin_components_revert() */
        '#submit' => array(
          'features_admin_components_revert',
        ),
      );
    }
    if ($review) {
      $form['buttons']['review'] = array(
        '#type' => 'submit',
        '#value' => t('Mark as reviewed'),
        /* @see \features_admin_components_review() */
        '#submit' => array(
          'features_admin_components_review',
        ),
      );
    }
  }
  return $form;
}