You are here

function field_redirection_field_formatter_settings_summary in Field Redirection 7.2

Implements hook_field_formatter_settings_summary().

File

./field_redirection.module, line 143
Provides a field formatter to redirect to another path.

Code

function field_redirection_field_formatter_settings_summary($field, $instance, $view_mode) {
  $output = '';

  // Shortcuts to make the rest of the code simpler.
  $display = $instance['display'][$view_mode];
  $settings = $display['settings'];
  $codes = field_redirection_http_codes();

  // Display a "hair on fire" warning message if the view mode is not 'full'.
  if ($view_mode != 'full') {
    $bad_modes = array(
      'default' => 'Default',
      'teaser' => 'Teaser',
      'rss' => 'RSS',
      'search_index' => 'Search index',
      'search_result' => 'Search result',
      'diff_standard' => 'Revision comparison',
      'revision' => 'Revision',
      'token' => 'Token',
    );
    if (array_key_exists($view_mode, $bad_modes)) {
      $output .= '<h2>' . t('Danger, Will Robinson!') . '</h2>';
      $output .= '<p>' . t('The Redirect formatter should not be used with the ":mode" view mode, it works best when used with the ":full" view mode.', array(
        ':mode' => $bad_modes[$view_mode],
        ':full' => t('Full content'),
      )) . '</p>';
    }
    else {
      $output .= '<h3>' . t('Careful now!') . '</h3>';
      $output .= '<p>' . t('Be careful using the Redirect formatter with this view mode, it could lead to problems.') . '</p>';
    }
  }

  // Work out which redirection code was being used, default to "301".
  $code = 301;
  if (!empty($settings['code']) && isset($codes[$settings['code']])) {
    $code = $settings['code'];
  }
  $output .= t('Redirect method: @code', array(
    '@code' => $codes[$code],
  ));

  // Indicate if the option is used.
  if ($settings['404_if_empty']) {
    $output .= ' (404 if empty)';
  }

  // Show path rules if the page_restrictions option is enabled.
  if (!empty($settings['page_restrictions']) && !empty($settings['pages'])) {
    $output .= '<br />' . t('Redirect restricted to certain paths.');
  }
  return $output;
}