You are here

function theme_noderelationships_admin_settings_noderef in Node Relationships 6

Render the node reference extras form.

File

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

Code

function theme_noderelationships_admin_settings_noderef($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.view_settings.js');
  $js_settings = array(
    'mode' => 'noderef',
    'viewSettingsUrl' => url('admin/build/views/edit'),
    'defaultViewName' => NODERELATIONSHIPS_BACKREF_VIEW_NAME,
  );
  drupal_add_js(array(
    'nodeRelationships' => $js_settings,
  ), 'setting');
  $destination = drupal_get_destination();
  $headers = array(
    array(
      'data' => t('Reference field'),
    ),
    array(
      'data' => t('Referred types'),
    ),
    array(
      'data' => t('Required'),
      'class' => 'noderelationships-cell-center',
    ),
    array(
      'data' => t('Cardinality'),
      'class' => 'noderelationships-cell-center',
    ),
    array(
      'data' => t('Extra node reference widget features'),
    ),
  );
  if (isset($form['translate_and_reference'])) {

    // Display a warning if i18n module is not enabled, or not configured
    // for the "Translate and reference" feature to work properly.
    if (!module_exists('i18n')) {
      drupal_set_message(t('It is recommended to install the <a href="@i18n-url">Internationalization</a> module in order to take full advantage of the &quot;Translate and reference&quot; feature.', array(
        '@i18n-url' => 'http://drupal.org/project/i18n',
      )), 'warning');
    }
    elseif (!variable_get('i18n_translation_switch', 0)) {
      drupal_set_message(t('It is recommended to enable the &quot;Switch interface for translating&quot; option in the <a href="@i18n-admin">Multilingual system settings</a> page for the &quot;Translate and reference&quot; feature to work properly.', array(
        '@i18n-admin' => url('admin/settings/language/i18n'),
      )), 'warning');
    }
  }
  $rows = array();
  foreach ($form['#noderelationships-relations'] as $field_name => $relation_info) {
    $referenceable_types = $relation_info['referenceable_types'];
    $field = $relation_info['field'];
    $cells = array();

    // Node reference 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 = in_array($form['#noderelationships-type'], $referenceable_types) ? 'noderelationships-cell-noderef-self' : (empty($referenceable_types) ? 'noderelationships-cell-noderef-any' : 'noderelationships-cell-noderef');
    $cells[] = array(
      'data' => '<div class="' . $field_class . '">' . $field_cell . '</div>',
    );

    // Related types.
    $items = array();
    if (empty($referenceable_types)) {
      $type_cell = t('Any');
      $type_class = 'noderelationships-cell-referred';
      $items[] = '<div class="' . $type_class . '">' . $type_cell . '</div>';
    }
    else {
      foreach ($referenceable_types as $referred_type) {
        $type_url_str = str_replace('_', '-', $referred_type);
        $type_cell = noderelationships_get_localized_content_type_name($referred_type);
        if ($form['#noderelationships-type'] == $referred_type) {
          $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/backref');
          $type_class = 'noderelationships-cell-referred';
        }
        $items[] = '<div class="' . $type_class . '">' . $type_cell . '</div>';
      }
    }
    $cells[] = array(
      'data' => implode('', $items),
    );

    // 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',
    );

    // Extra settings for node reference fields are available only for the
    // nodereference_autocomplete widget.
    $extra_features = array();
    if (isset($form['search_and_reference_view'][$field_name])) {

      // Search and reference view.
      $extra_features[] = drupal_render($form['search_and_reference_view'][$field_name]);

      // View reference in new window.
      $extra_features[] = drupal_render($form['view_in_new_window'][$field_name]);

      // Edit reference.
      $extra_features[] = drupal_render($form['edit_reference'][$field_name]);

      // Create and reference.
      $extra_features[] = drupal_render($form['create_and_reference'][$field_name]);

      // Translate and reference.
      if (isset($form['translate_and_reference'])) {
        $extra_features[] = drupal_render($form['translate_and_reference'][$field_name]);
      }
    }
    if (empty($extra_features)) {
      $extra_features[] = t('These options are available only for node reference autocomplete widgets.');
    }
    $cells[] = array(
      'data' => implode('', $extra_features),
      'class' => 'noderelationships-cell-options',
    );
    $rows[] = array(
      'data' => $cells,
    );
  }
  $output .= theme('table', $headers, $rows, array(
    'id' => 'noderelationships-settings-table',
  ));
  $output .= drupal_render($form);
  return $output;
}