diff --git a/core/modules/field_ui/src/DisplayOverview.php b/core/modules/field_ui/src/DisplayOverview.php index 137449461934078bda65ac6a84f17c38f0351bc4..96d6a9f7c26865b54223df3c702cd0e0f8c4d077 100644 --- a/core/modules/field_ui/src/DisplayOverview.php +++ b/core/modules/field_ui/src/DisplayOverview.php @@ -79,12 +79,8 @@ public function getFormId() { /** * {@inheritdoc} */ - public function buildForm(array $form, FormStateInterface $form_state, $entity_type_id = NULL, $bundle = NULL) { - if ($this->getRequest()->attributes->has('view_mode_name')) { - $this->mode = $this->getRequest()->attributes->get('view_mode_name'); - } - - return parent::buildForm($form, $form_state, $entity_type_id, $bundle); + public function buildForm(array $form, FormStateInterface $form_state, $entity_type_id = NULL, $bundle = NULL, $view_mode_name = 'default') { + return parent::buildForm($form, $form_state, $entity_type_id, $bundle, $view_mode_name); } /** diff --git a/core/modules/field_ui/src/DisplayOverviewBase.php b/core/modules/field_ui/src/DisplayOverviewBase.php index d41c7cb6a712f9440c2dc769d8a11dbb8ee0be22..541500e511572861aa02e0f542be855278f373b7 100644 --- a/core/modules/field_ui/src/DisplayOverviewBase.php +++ b/core/modules/field_ui/src/DisplayOverviewBase.php @@ -117,12 +117,10 @@ protected function getFieldDefinitions() { /** * {@inheritdoc} */ - public function buildForm(array $form, FormStateInterface $form_state, $entity_type_id = NULL, $bundle = NULL) { + public function buildForm(array $form, FormStateInterface $form_state, $entity_type_id = NULL, $bundle = NULL, $mode = 'default') { parent::buildForm($form, $form_state, $entity_type_id, $bundle); - if (empty($this->mode)) { - $this->mode = 'default'; - } + $this->mode = $mode; $field_definitions = $this->getFieldDefinitions(); $extra_fields = $this->getExtraFields(); diff --git a/core/modules/field_ui/src/FormDisplayOverview.php b/core/modules/field_ui/src/FormDisplayOverview.php index c317fd55854faee6ab28130de611fb2c0e4c52b5..05db56ba05dadc40eed1e084c55fdf43e13e75eb 100644 --- a/core/modules/field_ui/src/FormDisplayOverview.php +++ b/core/modules/field_ui/src/FormDisplayOverview.php @@ -78,12 +78,8 @@ public function getFormId() { /** * {@inheritdoc} */ - public function buildForm(array $form, FormStateInterface $form_state, $entity_type_id = NULL, $bundle = NULL) { - if ($this->getRequest()->attributes->has('form_mode_name')) { - $this->mode = $this->getRequest()->attributes->get('form_mode_name'); - } - - return parent::buildForm($form, $form_state, $entity_type_id, $bundle); + public function buildForm(array $form, FormStateInterface $form_state, $entity_type_id = NULL, $bundle = NULL, $form_mode_name = 'default') { + return parent::buildForm($form, $form_state, $entity_type_id, $bundle, $form_mode_name); } /** diff --git a/core/modules/system/tests/modules/entity_test/src/Controller/EntityTestController.php b/core/modules/system/tests/modules/entity_test/src/Controller/EntityTestController.php index d189747f4e54dcc2eae5cff4f515da5d0aa14a38..8154d53d2dd611a523360f7fdee45cacac81448d 100644 --- a/core/modules/system/tests/modules/entity_test/src/Controller/EntityTestController.php +++ b/core/modules/system/tests/modules/entity_test/src/Controller/EntityTestController.php @@ -47,7 +47,7 @@ public static function create(ContainerInterface $container) { /** * Displays the 'Add new entity_test' form. * - * @param string $entity_type + * @param string $entity_type_id * Name of the entity type for which a create form should be displayed. * * @return array @@ -55,10 +55,10 @@ public static function create(ContainerInterface $container) { * * @see \Drupal\entity_test\Routing\EntityTestRoutes::routes() */ - public function testAdd($entity_type) { - $entity = entity_create($entity_type, array()); + public function testAdd($entity_type_id) { + $entity = entity_create($entity_type_id, array()); $form = $this->entityFormBuilder()->getForm($entity); - $form['#title'] = $this->t('Create an @type', array('@type' => $entity_type)); + $form['#title'] = $this->t('Create an @type', array('@type' => $entity_type_id)); return $form; } @@ -67,14 +67,16 @@ public function testAdd($entity_type) { * * @param \Symfony\Component\HttpFoundation\Request $request * The request object to get entity type from. + * @param string $entity_type_id + * The entity type ID. * * @return array * The processed form for the edited entity. * * @see \Drupal\entity_test\Routing\EntityTestRoutes::routes() */ - public function testEdit(Request $request) { - $entity = $request->attributes->get($request->attributes->get('_entity_type')); + public function testEdit(Request $request, $entity_type_id) { + $entity = $request->attributes->get($entity_type_id); $form = $this->entityFormBuilder()->getForm($entity); $form['#title'] = $entity->label(); return $form; diff --git a/core/modules/system/tests/modules/entity_test/src/Routing/EntityTestRoutes.php b/core/modules/system/tests/modules/entity_test/src/Routing/EntityTestRoutes.php index 5902b09f59684234d59acf06feb72a045e196e0e..ec1d830142cf548584bba9dd356cfb1e1483292f 100644 --- a/core/modules/system/tests/modules/entity_test/src/Routing/EntityTestRoutes.php +++ b/core/modules/system/tests/modules/entity_test/src/Routing/EntityTestRoutes.php @@ -26,24 +26,24 @@ public function routes() { $types[] = 'entity_test_no_id'; $routes = array(); - foreach ($types as $entity_type) { - $routes["entity.$entity_type.add_form"] = new Route( - "$entity_type/add", - array('_content' => '\Drupal\entity_test\Controller\EntityTestController::testAdd', 'entity_type' => $entity_type), + foreach ($types as $entity_type_id) { + $routes["entity.$entity_type_id.add_form"] = new Route( + "$entity_type_id/add", + array('_content' => '\Drupal\entity_test\Controller\EntityTestController::testAdd', 'entity_type_id' => $entity_type_id), array('_permission' => 'administer entity_test content') ); - $routes["entity.$entity_type.edit_form"] = new Route( - "$entity_type/manage/{" . $entity_type . '}', - array('_content' => '\Drupal\entity_test\Controller\EntityTestController::testEdit', '_entity_type' => $entity_type), + $routes["entity.$entity_type_id.edit_form"] = new Route( + "$entity_type_id/manage/{" . $entity_type_id . '}', + array('_content' => '\Drupal\entity_test\Controller\EntityTestController::testEdit', 'entity_type_id' => $entity_type_id), array('_permission' => 'administer entity_test content'), array('parameters' => array( - $entity_type => array('type' => 'entity:' . $entity_type), + $entity_type_id => array('type' => 'entity:' . $entity_type_id), )) ); - $routes["entity.$entity_type.admin_form"] = new Route( - "$entity_type/structure/{bundle}", + $routes["entity.$entity_type_id.admin_form"] = new Route( + "$entity_type_id/structure/{bundle}", array('_content' => '\Drupal\entity_test\Controller\EntityTestController::testAdmin'), array('_permission' => 'administer entity_test content') ); diff --git a/core/modules/views_ui/src/ViewFormBase.php b/core/modules/views_ui/src/ViewFormBase.php index 39f1a0dce01c4c4d78ac8aaee65e6ad8b4f63481..77470782dd2ef3b96723d265aad8c89b9cf95357 100644 --- a/core/modules/views_ui/src/ViewFormBase.php +++ b/core/modules/views_ui/src/ViewFormBase.php @@ -30,15 +30,22 @@ abstract class ViewFormBase extends EntityForm { public function init(FormStateInterface $form_state) { parent::init($form_state); - if ($display_id = \Drupal::request()->attributes->get('display_id')) { - $this->displayID = $display_id; - } - // @todo Remove the need for this. $form_state->loadInclude('views_ui', 'inc', 'admin'); $form_state->set('view', $this->entity); } + /** + * {@inheritdoc} + */ + public function buildForm(array $form, FormStateInterface $form_state, $display_id = NULL) { + if (isset($display_id) && $form_state->has('display_id') && ($display_id !== $form_state->get('display_id'))) { + throw new \InvalidArgumentException('Mismatch between $form_state->get(\'display_id\') and $display_id.'); + } + $this->displayID = $form_state->has('display_id') ? $form_state->get('display_id') : $display_id; + return parent::buildForm($form, $form_state); + } + /** * {@inheritdoc} */ diff --git a/core/modules/views_ui/src/ViewPreviewForm.php b/core/modules/views_ui/src/ViewPreviewForm.php index f132b6424d33d824b3fb44c744e7162dc316850f..bdfb80f5513f413e98dd8329fba2712bc56260f0 100644 --- a/core/modules/views_ui/src/ViewPreviewForm.php +++ b/core/modules/views_ui/src/ViewPreviewForm.php @@ -8,40 +8,12 @@ namespace Drupal\views_ui; use Drupal\Core\Form\FormStateInterface; -use Drupal\user\TempStoreFactory; -use Symfony\Component\DependencyInjection\ContainerInterface; /** * Form controller for the Views preview form. */ class ViewPreviewForm extends ViewFormBase { - /** - * The views temp store. - * - * @var \Drupal\user\TempStore - */ - protected $tempStore; - - /** - * Constructs a new ViewPreviewForm object. - * - * @param \Drupal\user\TempStoreFactory $temp_store_factory - * The factory for the temp store object. - */ - public function __construct(TempStoreFactory $temp_store_factory) { - $this->tempStore = $temp_store_factory->get('views'); - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container) { - return new static( - $container->get('user.tempstore') - ); - } - /** * {@inheritdoc} */ @@ -129,15 +101,6 @@ protected function actions(array $form, FormStateInterface $form_state) { * Form submission handler for the Preview button. */ public function submitPreview($form, FormStateInterface $form_state) { - // Rebuild the form with a pristine $view object. - $view = $this->entity; - // Attempt to load the view from temp store, otherwise create a new one. - if (!$new_view = $this->tempStore->get($view->id())) { - $new_view = new ViewUI($view); - } - $build_info = $form_state->getBuildInfo(); - $build_info['args'][0] = $new_view; - $form_state->setBuildInfo($build_info); $form_state->set('show_preview', TRUE); $form_state->setRebuild(); }