If path-field is hidden in form display, in sidebar navigation it still displayed on node add/edit form.

Screenshot 2275463_field-enabled.png shows the node/add/page form as by default. After hiding the field in the default form display, the form is shown as 2275463_field-disabled.png. Notice the empty 'Url path settings' section. This patch fixes this issue, as shown in 2275463_field-disabled-patched.png.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

andypost’s picture

Title: Path field did not respect settings in form display » Path field does not respect settings in form display
Issue tags: +#d8ux
SpadXIII’s picture

Just ran into this issue myself and made a small patch.
I looked at the node module and saw it was doing an isset($form['uid']) there, so I applied the same style of logic in the path module's form alter. It now only adds the details-fieldset if the field already exists in the form.

andypost’s picture

Status: Active » Needs review
andypost’s picture

Issue tags: +Needs tests
SpadXIII’s picture

Issue tags: -Needs tests
FileSize
2.23 KB

I've written a test that, with a bit of help from chx. :)

It first asserts if the details-tag id and the field exist. Then removes the path alias field from the form display and checks again if they are gone.

SpadXIII’s picture

Issue summary: View changes
FileSize
70.47 KB
62.24 KB
SpadXIII’s picture

Issue summary: View changes
FileSize
62.44 KB
SpadXIII’s picture

FileSize
62.44 KB
SpadXIII’s picture

FileSize
59.79 KB
filijonka’s picture

Status: Needs review » Reviewed & tested by the community

great work spadXIII, no problem this one.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

The test does not fail when the changes to core/modules/path/path.module are not applied.

SpadXIII’s picture

Status: Needs work » Needs review
FileSize
1.57 KB
2.23 KB

Also added the test in a separate file for easier testing.

The last submitted patch, 12: 2275463-12-test-only.patch, failed testing.

alexpott’s picture

Status: Needs review » Reviewed & tested by the community

Thanks @SpadXIII for proving me wrong!

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

So thinking about this issue has led me to file #2378947: Hiding a field using form modes should not remove it from the form object - we should just be setting #access to whatever the path field has here (once that lands)

+++ b/core/modules/path/src/Tests/PathNodeFormTest.php
@@ -0,0 +1,54 @@
+ * Contains \Drupal\path\Tests\PathAdminTest.

Lol so this is why I thought the test passed with the patch... I copy and paste this to run the test from the command line... and here we have a copy and paste error!

SpadXIII’s picture

Indeed a copy-paste error. Next to that, if a field is not removed from the form object but access-false, my patch won't fix anything. Will update tonight!

SpadXIII’s picture

FileSize
1.57 KB
2.25 KB

Changed the module to account for the #access false, by doing an !empty() check.
Also fixed the file-comment :)

SpadXIII’s picture

Status: Needs work » Needs review

*note to self* don't forget to change status to needs review when adding new patches....

The last submitted patch, 17: 2275463-17-test-only.patch, failed testing.

alexpott’s picture

Status: Needs review » Needs work
+++ b/core/modules/path/path.module
@@ -42,7 +42,7 @@ function path_help($route_name, RouteMatchInterface $route_match) {
+  if ($node->hasField('path') && $node->get('path')->access('edit') && !empty($form['path']['#access'])) {

Actually this condition should be done with a #access too... ie. $form['path_settings']['#access'] = $node->hasField('path') && $node->get('path')->access('edit') && !empty($form['path']['#access']);

This means that your element can be altered by any other module without having to check it is there.

SpadXIII’s picture

FileSize
3.04 KB

I think I understood what you were saying, changed that in the patch. The fieldset is always added in the $form, with the if-statement for the #access.
I also changed the order of the checks; the cheaper empty-check first.

The test is unchanged.

SpadXIII’s picture

Status: Needs work » Needs review
chx’s picture

Status: Needs review » Reviewed & tested by the community

Looks good. Please post an interdiff next time.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Regardless of what happens in #2378947: Hiding a field using form modes should not remove it from the form object this looks good. This issue is a normal bug fix, and doesn't include any disruptive changes, so it is allowed per https://www.drupal.org/core/beta-changes. Committed 821a9ce and pushed to 8.0.x. Thanks!

  • alexpott committed 821a9ce on 8.0.x
    Issue #2275463 by SpadXIII: Path field does not respect settings in form...

Status: Fixed » Closed (fixed)

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