summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2014-10-15 10:26:18 (GMT)
committerAlex Pott2014-10-15 10:26:18 (GMT)
commit6b265331ea5d2f008ca1d70fef0f9dc824f57f50 (patch)
treed40fcead8f24c5f175dc5c4a7218cafe2979aef9
parent8f3f79ad34fcdc6db7b5bbb34f083a103ca4502c (diff)
Issue #2238981 by dawehner, effulgentsia, tim.plunkett: Change controllers to receive route parameters in their signature rather than via $request->attributes.
-rw-r--r--core/modules/field_ui/src/DisplayOverview.php8
-rw-r--r--core/modules/field_ui/src/DisplayOverviewBase.php6
-rw-r--r--core/modules/field_ui/src/FormDisplayOverview.php8
-rw-r--r--core/modules/system/tests/modules/entity_test/src/Controller/EntityTestController.php14
-rw-r--r--core/modules/system/tests/modules/entity_test/src/Routing/EntityTestRoutes.php20
-rw-r--r--core/modules/views_ui/src/ViewFormBase.php15
-rw-r--r--core/modules/views_ui/src/ViewPreviewForm.php37
7 files changed, 35 insertions, 73 deletions
diff --git a/core/modules/field_ui/src/DisplayOverview.php b/core/modules/field_ui/src/DisplayOverview.php
index 1374494..96d6a9f 100644
--- a/core/modules/field_ui/src/DisplayOverview.php
+++ b/core/modules/field_ui/src/DisplayOverview.php
@@ -79,12 +79,8 @@ class DisplayOverview extends DisplayOverviewBase {
/**
* {@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 d41c7cb..541500e 100644
--- a/core/modules/field_ui/src/DisplayOverviewBase.php
+++ b/core/modules/field_ui/src/DisplayOverviewBase.php
@@ -117,12 +117,10 @@ abstract class DisplayOverviewBase extends OverviewBase {
/**
* {@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 c317fd5..05db56b 100644
--- a/core/modules/field_ui/src/FormDisplayOverview.php
+++ b/core/modules/field_ui/src/FormDisplayOverview.php
@@ -78,12 +78,8 @@ class FormDisplayOverview extends DisplayOverviewBase {
/**
* {@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 d189747..8154d53 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 @@ class EntityTestController extends ControllerBase {
/**
* 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 @@ class EntityTestController extends ControllerBase {
*
* @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 @@ class EntityTestController extends ControllerBase {
*
* @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 5902b09..ec1d830 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 @@ class EntityTestRoutes {
$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 39f1a0d..7747078 100644
--- a/core/modules/views_ui/src/ViewFormBase.php
+++ b/core/modules/views_ui/src/ViewFormBase.php
@@ -30,10 +30,6 @@ 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);
@@ -42,6 +38,17 @@ abstract class ViewFormBase extends EntityForm {
/**
* {@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}
+ */
protected function prepareEntity() {
// Determine the displays available for editing.
if ($tabs = $this->getDisplayTabs($this->entity)) {
diff --git a/core/modules/views_ui/src/ViewPreviewForm.php b/core/modules/views_ui/src/ViewPreviewForm.php
index f132b64..bdfb80f 100644
--- a/core/modules/views_ui/src/ViewPreviewForm.php
+++ b/core/modules/views_ui/src/ViewPreviewForm.php
@@ -8,8 +8,6 @@
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.
@@ -17,32 +15,6 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
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}
*/
public function form(array $form, FormStateInterface $form_state) {
@@ -129,15 +101,6 @@ class ViewPreviewForm extends ViewFormBase {
* 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();
}