You are here

function theme_noderelationships_admin_settings_backref in Node Relationships 6

Render the back reference settings form.

File

./noderelationships.admin.inc, line 608
Implementation of the administration pages of the module.

Code

function theme_noderelationships_admin_settings_backref($form) {
  if (!isset($form['help'])) {
    return drupal_render($form);
  }
  $output = drupal_render($form['help']);
  $module_path = drupal_get_path('module', 'noderelationships');
  drupal_add_css($module_path . '/css/noderelationships.admin_settings.css');
  drupal_add_js($module_path . '/js/admin.drag.js');
  drupal_add_js($module_path . '/js/admin.view_settings.js');
  $js_settings = array(
    'mode' => 'backref',
    'viewSettingsUrl' => url('admin/build/views/edit'),
    'defaultViewName' => NODERELATIONSHIPS_BACKREF_VIEW_NAME,
  );
  drupal_add_js(array(
    'nodeRelationships' => $js_settings,
  ), 'setting');
  jquery_ui_add(array(
    'effects.transfer',
  ));
  $destination = drupal_get_destination();
  $headers = array(
    array(
      'data' => '',
    ),
    array(
      'data' => t('Weight'),
      'class' => 'noderelationships-cell-weight',
    ),
    array(
      'data' => t('Referrer type/field'),
    ),
    array(
      'data' => t('Required'),
      'class' => 'noderelationships-cell-center',
    ),
    array(
      'data' => t('Cardinality'),
      'class' => 'noderelationships-cell-center',
    ),
    array(
      'data' => t('Back reference view'),
    ),
    array(
      'data' => t('Back reference field'),
    ),
    array(
      'data' => t('Region'),
      'class' => 'noderelationships-cell-region',
    ),
  );
  $headers_count = count($headers);
  $backref_fields = noderelationships_get_backreferences($form['#noderelationships-type']);
  $regions = noderelationships_get_back_reference_regions() + array(
    'none' => t('Disabled'),
  );
  $rows = array();
  foreach ($form['#noderelationships-regions'] as $region => $region_relations) {
    $rows[] = array(
      'data' => array(
        array(
          'data' => $regions[$region],
          'class' => 'region',
          'colspan' => $headers_count,
        ),
      ),
      'class' => 'region region-' . $region,
    );
    $rows[] = array(
      'data' => array(
        array(
          'data' => '<em>' . t('No items in this region') . '</em>',
          'colspan' => $headers_count,
        ),
      ),
      'class' => 'region-message region-' . $region . '-message region-' . (empty($region_relations) ? 'empty' : 'populated'),
    );
    drupal_add_tabledrag('noderelationships-settings-table', 'match', 'sibling', 'noderelationships-region-select', 'noderelationships-region-' . $region);
    drupal_add_tabledrag('noderelationships-settings-table', 'order', 'sibling', 'noderelationships-weight', 'noderelationships-weight-' . $region);
    foreach ($region_relations as $relation_key => $relation_info) {
      $field_name = $relation_info['field_name'];
      $field = $relation_info['field'];
      $cells = array();

      // Drag'n'drop handle, Weight and Back reference region.
      $cells[] = array(
        'data' => '',
      );
      $cells[] = array(
        'data' => drupal_render($form['weight'][$relation_key]),
        'class' => 'noderelationships-cell-weight',
      );

      // Referrer type.
      $type_url_str = str_replace('_', '-', $field['type_name']);
      $type_cell = noderelationships_get_localized_content_type_name($field['type_name']);
      if ($form['#noderelationships-type'] == $field['type_name']) {
        $type_cell = check_plain($type_cell);
        $type_class = 'noderelationships-cell-current-self';
      }
      else {
        $type_cell = l($type_cell, 'admin/content/node-type/' . $type_url_str . '/relationships/noderef');
        $type_class = 'noderelationships-cell-referrer';
      }

      // Referrer field.
      $type_url_str = str_replace('_', '-', $field['type_name']);
      $field_cell = l($field['widget']['label'], 'admin/content/node-type/' . $type_url_str . '/fields/' . $field_name, array(
        'query' => $destination,
      ));
      $field_class = $form['#noderelationships-type'] == $field['type_name'] ? 'noderelationships-cell-noderef-self' : 'noderelationships-cell-noderef';

      // Referrer type/field.
      $cells[] = array(
        'data' => '<div class="' . $type_class . '">' . $type_cell . ' / ' . $field_cell . '</div>',
      );

      // Required.
      $cells[] = array(
        'data' => $field['required'] ? t('Yes') : t('No'),
        'class' => 'noderelationships-cell-center',
      );

      // Cardinality.
      $cells[] = array(
        'data' => empty($field['multiple']) ? 1 : ($field['multiple'] == 1 ? t('Unlimited') : (int) $field['multiple']),
        'class' => 'noderelationships-cell-center',
      );

      // Back reference view.
      $cells[] = array(
        'data' => drupal_render($form['back_reference_view'][$relation_key]),
        'class' => 'noderelationships-cell-options',
      );

      // Back reference region.
      $cells[] = array(
        'data' => drupal_render($form['back_reference_region'][$relation_key]),
        'class' => 'noderelationships-cell-region',
      );

      // Back reference field.
      $backref_field_name = noderelationships_cck_backref_build_name($form['#noderelationships-type'], $field['type_name'], $field_name);
      if (isset($backref_fields[$backref_field_name])) {
        $type_url_str = str_replace('_', '-', $form['#noderelationships-type']);
        $backref_label = $backref_fields[$backref_field_name]['widget_label'];
        $backref_cell = l($backref_label, 'admin/content/node-type/' . $type_url_str . '/fields/' . $backref_field_name, array(
          'query' => $destination,
        ));
      }
      else {
        $backref_label = t('Back references from @referrer-label in @referrer-type', array(
          '@referrer-label' => $field['widget']['label'],
          '@referrer-type' => noderelationships_get_localized_content_type_name($field['type_name']),
        ));
        $backref_cell = '<span title="' . t('This field will be automatically created when the form is submitted.') . '">' . $backref_label . '</span>';
      }
      $cells[] = array(
        'data' => $backref_cell,
        'class' => 'noderelationships-cell-field',
      );
      $rows[] = array(
        'data' => $cells,
        'class' => 'draggable noderelationships-region-' . $region,
      );
    }
  }
  $output .= theme('table', $headers, $rows, array(
    'id' => 'noderelationships-settings-table',
  ));
  $output .= drupal_render($form);
  return $output;
}