You are here

function features_admin_components in Features 7

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

Display the components of a feature.

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

File

./features.admin.inc, line 507
@todo.

Code

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

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

  // 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];
    }
    else {
      if (array_key_exists($component, $conflicts)) {
        $storage = FEATURES_CONFLICT;
      }
    }
    $form['components'][$component] = array(
      '#markup' => 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'),
        '#submit' => array(
          'features_admin_components_revert',
        ),
      );
    }
    if ($review) {
      $form['buttons']['review'] = array(
        '#type' => 'submit',
        '#value' => t('Mark as reviewed'),
        '#submit' => array(
          'features_admin_components_review',
        ),
      );
    }
  }
  return $form;
}