Support from Acquia helps fund testing for Drupal Acquia logo

Comments

effulgentsia’s picture

Title: Change ViewPageController::handle() to receive parameters in the signature rather than via $request->attributes » Change controllers to receive route parameters in their signature rather than via $request->attributes
Component: views.module » routing system

Broadening scope to also include views_ui, field_ui, and content_translation. These are all the instances I could find in core/modules.

effulgentsia’s picture

FileSize
10.98 KB

Patch for #1.

Status: Needs review » Needs work

The last submitted patch, 2: controller-signature.patch, failed testing.

dawehner’s picture

dawehner’s picture

All the other changes looks certainly reasonable and should have been like that in the first place.

dawehner’s picture

Status: Needs work » Needs review
FileSize
4.98 KB

Reroll

Status: Needs review » Needs work

The last submitted patch, 6: attributes-2238981-6.patch, failed testing.

effulgentsia’s picture

Status: Needs work » Needs review
FileSize
5.26 KB
855 bytes

ViewsUIController::edit() passes $display_id in via $form_state rather than $form_state['build_info']['args']. Not sure if that's correct or not, but here's a fix/hack to accommodate that.

Status: Needs review » Needs work

The last submitted patch, 8: attributes-2238981-8.patch, failed testing.

effulgentsia’s picture

Status: Needs work » Needs review
FileSize
6.19 KB
786 bytes

Looks like we had some dead code getting in the way.

dawehner’s picture

Rerolled against a recent rename of a lot of classes and removed more dead code in ViewPreviewForm

  1. +++ b/core/modules/views_ui/lib/Drupal/views_ui/ViewFormControllerBase.php
    @@ -41,6 +37,17 @@ public function init(array &$form_state) {
    +    if (isset($display_id) && isset($form_state['display_id']) && ($display_id !== $form_state['display_id'])) {
    +      throw new \InvalidArgumentException('Mismatch between $form_state[\'display_id\'] and $display_id.');
    +    }
    +    $this->displayID = isset($form_state['display_id']) ? $form_state['display_id'] : $display_id;
    

    Is this exception just temporary for debugging?

  2. +++ b/core/modules/views_ui/lib/Drupal/views_ui/ViewPreviewFormController.php
    @@ -127,13 +127,6 @@ protected function actions(array $form, array &$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);
    -    }
    -    $form_state['build_info']['args'][0] = $new_view;
    

    This seems to be a valid removal, given that the tempstore is converted as defined in the routing.yml file.

dawehner’s picture

11: attributes-2238981-11.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, 11: attributes-2238981-11.patch, failed testing.

tim.plunkett’s picture

tim.plunkett’s picture

Status: Needs work » Needs review
FileSize
7.82 KB

Rerolled.

Status: Needs review » Needs work

The last submitted patch, 16: request-2238981-16.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
FileSize
7.06 KB

Rerolled.

Status: Needs review » Needs work

The last submitted patch, 18: 2238981-18.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
FileSize
7.07 KB
1.12 KB

Let's fix it.

Crell’s picture

Status: Needs review » Reviewed & tested by the community

This seems reasonable to me. The less controllers directly access $request, the better.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

Minor nit alert:

+++ b/core/modules/field_ui/src/DisplayOverview.php
@@ -78,11 +78,8 @@ public function getFormId() {
   /**
    * {@inheritdoc}
    */
...
+  public function buildForm(array $form, FormStateInterface $form_state, $entity_type_id = NULL, $bundle = NULL, $view_mode_name = NULL) {
+    $this->mode = $view_mode_name;
     return parent::buildForm($form, $form_state, $entity_type_id, $bundle);

+++ b/core/modules/field_ui/src/FormDisplayOverview.php
@@ -77,11 +77,8 @@ public function getFormId() {
   /**
    * {@inheritdoc}
    */
...
+    $this->mode = $form_mode_name;
     return parent::buildForm($form, $form_state, $entity_type_id, $bundle);

Let's pass the mode into the parent buildForm so that {inheritdoc} is correct.

dawehner’s picture

Status: Needs work » Needs review
FileSize
8.05 KB
2.2 KB

Sure, let's do that.

Status: Needs review » Needs work

The last submitted patch, 23: 2238981-23.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
FileSize
1.21 KB
8.16 KB

This could be it.

catch’s picture

  1. +++ b/core/modules/field_ui/src/DisplayOverview.php
    @@ -79,12 +79,9 @@ public function getFormId() {
    +  public function buildForm(array $form, FormStateInterface $form_state, $entity_type_id = NULL, $bundle = NULL, $view_mode_name = NULL) {
    

    Why not $view_mode_name = 'default' and save the ternary on the next line?

  2. +++ b/core/modules/field_ui/src/FormDisplayOverview.php
    @@ -78,12 +78,9 @@ public function getFormId() {
    +  public function buildForm(array $form, FormStateInterface $form_state, $entity_type_id = NULL, $bundle = NULL, $form_mode_name = NULL) {
    

    $form_mode_name/$view_mode_name mismatch.

  3. +++ b/core/modules/system/tests/modules/entity_test/src/Controller/EntityTestController.php
    @@ -67,14 +67,16 @@ public function testAdd($entity_type) {
    +    $entity = $request->attributes->get($_entity_type_id);
    

    Still have to get the entity out of the Request attributes here?

Status: Needs review » Needs work

The last submitted patch, 25: 2238981-25.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
FileSize
8.06 KB
1.5 KB

$form_mode_name/$view_mode_name mismatch.

ups

Still have to get the entity out of the Request attributes here?

Well, we have one controller for multiple entity types here.

dawehner’s picture

$form_mode_name/$view_mode_name mismatch.

ups

Still have to get the entity out of the Request attributes here?

Well, we have one controller for multiple entity types here.

effulgentsia’s picture

+++ b/core/modules/system/tests/modules/entity_test/src/Controller/EntityTestController.php
@@ -67,14 +67,16 @@ public function testAdd($entity_type) {
+   * @param string $_entity_type_id
+   *   The entity type ID.

Should we make testAdd() and testEdit() match? Perhaps rename both to $entity_type_id (no leading underscore)?

dawehner’s picture

FileSize
10.22 KB
4.29 KB

Sure, this sounds like a good idea.

effulgentsia’s picture

Status: Needs review » Reviewed & tested by the community

Looks great.

Still have to get the entity out of the Request attributes here?

Search HEAD for $request->attributes->get($ as well as $route_match->getParameter($ and you'll see a few other similar usages. Opened #2356689: Decide on the proper way for core controllers to access a variably named route parameter for that.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 6b26533 and pushed to 8.0.x. Thanks!

  • alexpott committed 6b26533 on 8.0.x
    Issue #2238981 by dawehner, effulgentsia, tim.plunkett: Change...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.