diff --git a/core/modules/field_ui/lib/Drupal/field_ui/FieldUI.php b/core/modules/field_ui/lib/Drupal/field_ui/FieldUI.php new file mode 100644 index 0000000..6e4a6a2 --- /dev/null +++ b/core/modules/field_ui/lib/Drupal/field_ui/FieldUI.php @@ -0,0 +1,36 @@ +entityManager = $entity_manager; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('plugin.manager.entity') + ); + } + + /** * {@inheritdoc} */ public function buildForm(array $form, array &$form_state, FieldInstanceInterface $field_instance = NULL) { - parent::buildForm($form, $form_state, $field_instance); + $this->instance = $form_state['instance'] = $field_instance; + form_load_include($form_state, 'inc', 'field_ui', 'field_ui.admin'); $field = $this->instance->getField(); $form['#field'] = $field; @@ -144,9 +183,13 @@ public function submitForm(array &$form, array &$form_state) { try { $field->save(); drupal_set_message(t('Updated field %label field settings.', array('%label' => $this->instance->label()))); - $form_state['redirect'] = $this->getNextDestination(); + $next_destination = FieldUI::getNextDestination(); + if (empty($next_destination)) { + $next_destination = $this->entityManager->getAdminPath($this->instance->entity_type, $this->instance->bundle) . '/fields'; + } + $form_state['redirect'] = $next_destination; } - catch (Exception $e) { + catch (\Exception $e) { drupal_set_message(t('Attempt to update field %label failed: %message.', array('%label' => $this->instance->label(), '%message' => $e->getMessage())), 'error'); } } diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldInstanceFormBase.php b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldInstanceFormBase.php index a967781..2417292 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldInstanceFormBase.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldInstanceFormBase.php @@ -12,6 +12,7 @@ use Drupal\Core\Entity\EntityManager; use Drupal\field\Plugin\Type\Widget\WidgetPluginManager; use Drupal\field\FieldInstanceInterface; +use Drupal\field_ui\FieldUI; use Symfony\Component\DependencyInjection\ContainerInterface; abstract class FieldInstanceFormBase implements FormInterface, ControllerInterface { @@ -75,18 +76,11 @@ public function buildForm(array $form, array &$form_state, FieldInstanceInterfac * Either the next path, or an array of redirect paths. */ protected function getNextDestination() { - $destinations = !empty($_REQUEST['destinations']) ? $_REQUEST['destinations'] : array(); - if (!empty($destinations)) { - unset($_REQUEST['destinations']); - $path = array_shift($destinations); - $options = drupal_parse_url($path); - if ($destinations) { - $options['query']['destinations'] = $destinations; - } - return array($options['path'], $options); + $next_destination = FieldUI::getNextDestination(); + if (empty($next_destination)) { + $next_destination = $this->entityManager->getAdminPath($this->instance->entity_type, $this->instance->bundle) . '/fields'; } - $admin_path = $this->entityManager->getAdminPath($this->instance->entity_type, $this->instance->bundle); - return $admin_path . '/fields'; + return $next_destination; } }