You are here

function backports_redirect_to_field_edit_page in Backports 7

Menu callback to redirect to the page for editing a field.

This callback allows us to simplify the field UI by removing the (redundant) field settings page and replacing with the main field UI edit page (the one that allows editing the field and instance settings on the same screen).

Parameters

$instance: An array representing the field instance to be edited.

1 string reference to 'backports_redirect_to_field_edit_page'
backports_menu_alter in ./backports.module
Implements hook_menu_alter().

File

./backports.module, line 55
backports.module Hook implementations for Backports.

Code

function backports_redirect_to_field_edit_page($instance) {

  // By implementing this redirect, we achieve two things. First, we ensure
  // that if there are any links on the site pointing to the field settings
  // page, they will gracefully redirect the user to the new page instead.
  // Second, because the redirect goes to the edit screen directly (without any
  // query parameters in the URL), this ensures that the field UI will properly
  // treat it as the "last" (and only) step in the process of adding a new
  // field and immediately redirect back to the field overview form when
  // complete; see field_ui_next_destination(). This allows us to automatically
  // make the workflow for adding fields behave the way we want without having
  // to mess with submit handlers and $form_state['redirect'].
  $admin_path = _field_ui_bundle_admin_path($instance['entity_type'], $instance['bundle']);
  if (isset($admin_path)) {
    drupal_goto($admin_path . '/fields/' . $instance['field_name']);
  }
  else {
    return MENU_ACCESS_DENIED;
  }
}