You are here

function theme_relation_ui_admin_content in Relation 7

Generate a table of all relations on this site.

1 theme call to theme_relation_ui_admin_content()
relation_ui_admin_content in ./relation_ui.module
Menu callback for admin/content/relation. Displays all relations on the site.

File

./relation_ui.module, line 619
Provide administration interface for relation type bundles.

Code

function theme_relation_ui_admin_content($variables) {
  $relations = $variables['relations'];
  $header = $variables['header'];
  $types = relation_get_types();
  $rows = array();
  if (empty($relations)) {

    // Give a message if there are no relations returned.
    $message = t('There are currently no relations on your site.');
    $rows[] = array(
      array(
        'data' => $message,
        'colspan' => 5,
      ),
    );
  }
  else {
    foreach ($relations as $relation) {

      // Load the relation.
      $r = relation_load($relation->rid);

      // Get the endpoints for this relation.
      $endpoints = field_get_items('relation', $r, 'endpoints');
      $relation_entities = array();
      if (!empty($endpoints)) {
        foreach ($endpoints as $endpoint) {
          $entities = entity_load($endpoint['entity_type'], array(
            $endpoint['entity_id'],
          ));
          $entity = reset($entities);
          $title = entity_label($endpoint['entity_type'], $entity);
          $path = entity_uri($endpoint['entity_type'], $entity);

          // Logic to process how the different entities return a uri.
          // see this issue: http://drupal.org/node/1057242
          if ($endpoint['entity_type'] == 'file') {
            $path = array(
              'path' => file_create_url($path),
            );
          }
          if ($endpoint['entity_type'] == 'taxonomy_vocabulary') {
            $path = array(
              'path' => 'admin/structure/taxonomy/' . $entity->machine_name,
            );
          }
          $relation_entities[] = array(
            'title' => $title,
            'path' => $path['path'],
          );
        }
      }

      // Build the column for the relation entities.
      $relation_column = array();
      foreach ($relation_entities as $entity) {
        $relation_column[] = l($entity['title'], $entity['path']);
      }

      // Build the rows to pass to the table theme function.
      // Directional is implemented, not sure how well it works.
      $destination = drupal_get_destination();
      $options = array(
        'attributes' => array(),
        'query' => array(
          'destination' => $destination['destination'],
        ),
      );
      $endpoint_separator = ', ';
      $type_label = '';

      // Get the type for this relation
      if (isset($types[$r->relation_type])) {
        $type = $types[$r->relation_type];
        $endpoint_separator = $type->directional ? " → " : " ↔ ";
        $type_label = $relation->relation_type;
      }
      $relation_uri = entity_uri('relation', $relation);
      $rows[] = array(
        l(t('Relation') . ' ' . $relation->rid, $relation_uri['path']),
        $type_label,
        implode($endpoint_separator, $relation_column),
        user_access('edit relations') ? l(t('Edit'), $relation_uri['path'] . '/edit', $options) : '',
        user_access('delete relations') ? l(t('Delete'), $relation_uri['path'] . '/delete', $options) : '',
      );
    }
  }
  return theme('table', array(
    'header' => $header,
    'rows' => $rows,
  )) . theme('pager');
}