You are here

function conditional_fields_dependencies_overview_page in Conditional Fields 7.3

Dependencies administration page.

If the callback is called from the overview page, it builds a list of dependencies for each entity type, grouped by bundle. If called from one of the local tasks, it builds a list of dependencies only for the selected entity type. If called from a task under a specific bundle administration page, it builds a list just for that entity type and bundle name pair.

1 string reference to 'conditional_fields_dependencies_overview_page'
conditional_fields_menu in ./conditional_fields.module
Implements hook_menu().

File

includes/conditional_fields.admin.inc, line 17
Administration of dependencies.

Code

function conditional_fields_dependencies_overview_page($bundle_name = NULL, $entity_type = NULL) {

  // When displaying the page, make sure the list of fields is up-to-date.
  field_info_cache_clear();

  // Gather entities information.
  $entities = $entity_type ? array(
    $entity_type => entity_get_info($entity_type),
  ) : entity_get_info();

  // Extract bundle name from path, if present.
  if ($bundle_name) {
    $bundle_name = strtr($bundle_name, array(
      '-' => '_',
    ));

    // Hacky exception for hanlding comments.
    if ($entity_type == 'comment') {
      $bundle_name = 'comment_node_' . $bundle_name;
    }
  }

  // Unused here, but saves queries in conditional_fields_dependency_add_form().
  if (!$bundle_name) {
    conditional_fields_load_dependencies($entity_type, $bundle_name);
  }
  $build = array();
  if (!$entity_type) {
    $build['#attached']['library'][] = array(
      'system',
      'drupal.collapse',
    );
  }
  foreach ($entities as $entity_name => $entity_info) {
    if (!$entity_info['fieldable']) {
      continue;
    }
    $items = array();
    if ($entity_type) {
      $build[$entity_name] = array();
    }
    else {
      $build[$entity_name] = array(
        '#type' => 'fieldset',
        '#title' => $entity_info['label'],
        '#collapsible' => TRUE,
        '#collapsed' => TRUE,
        '#attributes' => array(
          'class' => array(
            'collapsible collapsed',
          ),
        ),
      );
    }
    if (empty($entity_info['bundles'])) {
      $build[$entity_name]['no_bundles'] = array(
        '#markup' => $entity_name == 'node' ? t('No content types available.') : t('No bundles available.'),
      );
    }
    else {
      foreach ($entity_info['bundles'] as $bundle_info_name => $bundle_info) {
        if ($bundle_name && $bundle_name != $bundle_info_name) {
          continue;
        }
        $build[$entity_name][$bundle_info_name] = array();
        if (!$bundle_name && count($entity_info['bundles']) > 1) {
          $build[$entity_name][$bundle_info_name]['title'] = array(
            '#markup' => '<h4 class="conditional-fields-bundles-list clearfix">' . $bundle_info['label'] . '</h4>',
          );
        }
        $build[$entity_name][$bundle_info_name] += drupal_get_form('conditional_fields_dependency_add_form_' . $entity_name . '_' . $bundle_info_name);
        if (!$entity_type && !isset($build[$entity_name][$bundle_info_name]['no_fields'])) {
          $build[$entity_name]['#collapsed'] = FALSE;
          $build[$entity_name]['#attributes']['class'] = array(
            'collapsible',
          );
        }
      }
    }
  }
  return $build;
}