Problem/Motivation

ShortcutForm uses the old pattern of checking whether it is an add or an update form to provide dedicated messages.
Also Shortcut module has some forms in \Drupal\shortcut\Form and some in \Drupal\shortcut which is kind of confusing and this mix needs a fix.

Proposed resolution

Split ShortcutForm into ShortcutAddForm and ShortcutEditForm instead

Remaining tasks

User interface changes

None.

API changes

None.

CommentFileSizeAuthor
#49 interdiff-2324873-44-46.txt2.07 KBjibran
#49 interdiff-2324873-42-44.txt1.67 KBjibran
#48 interdiff-2324873-42-46.txt4.86 KBdev.patrick
#48 interdiff-2324873-44-46.txt4.86 KBdev.patrick
#46 split_shortcutform_into-2324873-46.patch4.81 KBdev.patrick
#44 split_shortcutform_into-2324873-44.patch4.84 KBdev.patrick
#42 split_shortcutform_into-2324873-41.patch4.86 KBdev.patrick
#39 split_shortcutform_into-2324873-39.patch4.86 KBdev.patrick
#29 split_shortcutform_into-2324873-29.patch4.03 KBjibran
#28 interdiff-2324873-20-26.txt4.49 KBsidharthap
#26 shortcutform-2324873-26.patch4.83 KBsidharthap
#24 shortcutform-2324873-24.patch4.12 KBsidharthap
#21 2324873-21.patch4.37 KBnaveenvalecha
#21 interdiff-2324873-20-21.txt1.54 KBnaveenvalecha
#20 interdiff-2324873-15-20.txt878 bytesnaveenvalecha
#20 2324873-20.patch2.83 KBnaveenvalecha
#2 split_shortcutform_into-2324873-2.patch11.48 KBJeroenT
#6 split_shortcutForm_into-2324873-6.patch6.03 KBzuhair_ak
#12 2324873-12.patch4.27 KBtherealssj
#15 2324873-13.patch2.97 KBtherealssj
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

JeroenT’s picture

Assigned: Unassigned » JeroenT
Issue tags: +DUGBE1409

Working on this @ DUG Belgium

JeroenT’s picture

Assigned: JeroenT » Unassigned
Status: Active » Needs review
FileSize
11.48 KB

Created patch. I was unable to test it because of the following error when visiting url : admin/config/user-interface/shortcut

Twig_Error_Runtime: An exception has been thrown during the rendering of a template ("Route "field_ui.overview_shortcut" does not exist.") in "core/modules/system/templates/links.html.twig" at line 50. in Twig_Template->displayWithErrorHandling() (line 291 of core/vendor/twig/twig/lib/Twig/Template.php).

Status: Needs review » Needs work

The last submitted patch, 2: split_shortcutform_into-2324873-2.patch, failed testing.

jibran’s picture

zuhair_ak’s picture

Assigned: Unassigned » zuhair_ak
zuhair_ak’s picture

Split the ShortcutForm.php to ShortcutAddForm.php and ShortcutEditForm.php. Made the changes in the annotations in Entity folder files to reflect the changes.

vg3095’s picture

Status: Needs work » Needs review

Update to run the test bot

Status: Needs review » Needs work

The last submitted patch, 6: split_shortcutForm_into-2324873-6.patch, failed testing.

zuhair_ak’s picture

Version: 8.0.x-dev » 8.2.x-dev
Status: Needs work » Needs review
Related issues: +#2428003: Move all shortcut forms to \Drupal\shortcut\Form

This issue is dependant on the application of patch in - #2428003: Move all shortcut forms to \Drupal\shortcut\Form . Should we wait till that patch is applied?

jibran’s picture

You can combine the patches for now to get the proper test results.

tim.plunkett’s picture

  1. +++ b/core/modules/shortcut/shortcut.routing.yml
    @@ -57,7 +57,7 @@ shortcut.link_add:
     entity.shortcut.canonical:
       path: '/admin/config/user-interface/shortcut/link/{shortcut}'
    
    @@ -66,7 +66,7 @@ entity.shortcut.canonical:
     entity.shortcut.edit_form:
       path: '/admin/config/user-interface/shortcut/link/{shortcut}'
    

    Probably out of scope, but there shouldn't two of these

  2. +++ b/core/modules/shortcut/src/Entity/Shortcut.php
    @@ -26,9 +26,9 @@
    - *       "default" = "Drupal\shortcut\ShortcutForm",
    - *       "add" = "Drupal\shortcut\ShortcutForm",
    ...
    + *       "default" = "Drupal\shortcut\Form\ShortcutAddForm",
    + *       "add" = "Drupal\shortcut\Form\ShortcutAddForm",
    

    Can we please remove this form operation?

  3. +++ b/core/modules/shortcut/src/Entity/ShortcutSet.php
    @@ -22,9 +22,9 @@
    - *       "default" = "Drupal\shortcut\ShortcutSetForm",
    - *       "add" = "Drupal\shortcut\ShortcutSetForm",
    - *       "edit" = "Drupal\shortcut\ShortcutSetForm",
    + *       "default" = "Drupal\shortcut\Form\ShortcutSetForm",
    + *       "add" = "Drupal\shortcut\Form\ShortcutSetForm",
    + *       "edit" = "Drupal\shortcut\Form\ShortcutSetForm",
    

    This should let #2324877: Split ShortcutSetForm into ShortcutSetAddForm and ShortcutSetEditForm handle ShortcutSet and not move it

  4. +++ /dev/null
    @@ -1,46 +0,0 @@
    -    if ($status == SAVED_UPDATED) {
    -      $message = $this->t('The shortcut %link has been updated.', array('%link' => $entity->getTitle()));
    -    }
    -    else {
    -      $message = $this->t('Added a shortcut for %title.', array('%title' => $entity->getTitle()));
    -    }
    

    Honestly, this method is so simple I have no problem leaving it and won't fixing the issue.

There isn't sufficient motivation for this change in the issue summary.

therealssj’s picture

I don't quite see how this patch is dependent on #2428003: Move all shortcut forms to \Drupal\shortcut\Form
The tests must be failing because of some other reason.

I think we should set default form to edit the we wouldn't need to edit the routing.yml

@tim.plunkett
I don't quite understand what is mention in #11 4th comment.
Do you mean we should keep the same save() method in new ShortcutAddForm and ShortcutEditForm classes? ( This makes no sense though )

#11 1, Should we open a new issue for this?

New patch attached.

Status: Needs review » Needs work

The last submitted patch, 12: 2324873-12.patch, failed testing.

therealssj’s picture

Issue summary: View changes

Is this good enough summary update for motivation?

therealssj’s picture

We should not remove the ShortcutForm class here.
Patch fix.

therealssj’s picture

Status: Needs work » Needs review

Go test bot!

tim.plunkett’s picture

ShortcutForm uses the old pattern of checking whether it is an add or an update form to provide dedicated messages.

Who decided that it was an "old pattern", and that a newer pattern would be better?
I think this class is fine as is.

Moving it to another namespace is fine.

therealssj’s picture

Yes this does lead to redundant code.
The motivation for this might have been the fact that deleteform has a separate class but edit and add don't.

Though only changing the namespace seems fine and this should be closed as works as desgined and let the #2428003: Move all shortcut forms to \Drupal\shortcut\Form handle this.

Views?

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

naveenvalecha’s picture

naveenvalecha’s picture

Issue summary: View changes
FileSize
1.54 KB
4.37 KB
naveenvalecha’s picture

Issue summary: View changes

Updating issue summary.

jibran’s picture

Status: Needs review » Needs work
Issue tags: -Needs issue summary update

Thanks for rerolling the patch @naveenvalecha.

  1. +++ b/core/modules/shortcut/src/Form/ShortcutAddForm.php
    @@ -0,0 +1,33 @@
    + * Form handler for the shortcut Add entity forms.
    

    s/Add/add.

  2. +++ b/core/modules/shortcut/src/Form/ShortcutEditForm.php
    @@ -0,0 +1,33 @@
    + * Form handler for the shortcut Edit entity forms.
    

    s/Edit/edit.

  3. +++ /dev/null
    @@ -1,51 +0,0 @@
    -      $view_link = \Drupal::l($entity->getTitle(), $url);
    

    What about this?

sidharthap’s picture

Assigned: zuhair_ak » Unassigned
Status: Needs work » Needs review
FileSize
4.12 KB

Thank you @Jibran, Updated patch file as per #23. Entity title link based on access added back.

jibran’s picture

Thanks for fixing the feedback. I think we can remove


  /**
   * The entity being used by this form.
   *
   * @var \Drupal\shortcut\ShortcutInterface
   */
  protected $entity;

from both classes.

sidharthap’s picture

Thank you @Jibran, Updated patch as per #25.

jibran’s picture

Status: Needs review » Needs work

Thanks for the quick update. Can you please use git diff -M20 to create a patch?

sidharthap’s picture

Status: Needs work » Needs review
FileSize
4.49 KB

Thanks @Jibran.
Here is the diff file between #20 and #26

jibran’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
4.03 KB

I was asking about updating the patch like this. Anyways I rerolled the patch. Thank you for your contribution. I think this patch is RTBC now.

alexpott’s picture

Status: Reviewed & tested by the community » Needs review

Can someone explain how this falls into https://www.drupal.org/core/d8-allowed-changes? I'm not sure the current change is. But I might be wrong.

I think we can add the new forms but I'm not sure we can remove the old form - we need to deprecate it.

jibran’s picture

Status: Needs review » Reviewed & tested by the community
naveenvalecha’s picture

RTBC +1
Re: #30
Per https://www.drupal.org/core/d8-bc-policy#controllers The Form classes are internals


Please also do give credit to the peoples who have worked in the duplicate issue https://www.drupal.org/node/2428003
catch’s picture

@alexpott the form classes are entirely @internal so it should be fine.

We could add back the old class with a deprecation notice and not use it, but for me the likelihood of someone extending shortcut forms should be close to zero?

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs change record, +8.3.0 release notes

I think we need a change record here. The CR needs to explicit mention how a contrib module could support both 8.2.x and 8.3.x if they are extending these classes. As far as I can see the best way would be to just not extend the classes and do the functionality themselves.

webchick’s picture

Issue tags: -8.3.0 release notes

Removing 8.3.0 release notes for now, since this is not in 8.3.0 yet.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

jibran’s picture

Issue tags: +Needs reroll
dev.patrick’s picture

Adding rerolled patch. Only conflict while rebase was deleted file ShortcutForm.php.

dev.patrick’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 39: split_shortcutform_into-2324873-39.patch, failed testing. View results

dev.patrick’s picture

Status: Needs work » Needs review
FileSize
4.86 KB
jibran’s picture

Status: Needs review » Needs work
Issue tags: -Needs reroll

Thanks, for the reroll.

+++ b/core/modules/shortcut/src/Form/ShortcutAddForm.php
@@ -0,0 +1,36 @@
+    $message = $this->t('Added a shortcut for %title.', array('%title' => $view_link));
...
+    $form_state->setRedirect('entity.shortcut_set.customize_form', array('shortcut_set' => $entity->bundle()));

+++ b/core/modules/shortcut/src/Form/ShortcutEditForm.php
@@ -0,0 +1,36 @@
+    $message = $this->t('The shortcut %link has been updated.', array('%link' => $view_link));
...
+    $form_state->setRedirect('entity.shortcut_set.customize_form', array('shortcut_set' => $entity->bundle()));

We are not using short version of array now.

dev.patrick’s picture

Status: Needs work » Needs review
FileSize
4.84 KB

Thanks Jibran, corrected your mentions.

jibran’s picture

Thanks for the fixes. Please also upload the interdiff.

  1. +++ b/core/modules/shortcut/src/Form/ShortcutAddForm.php
    @@ -0,0 +1,36 @@
    +      $view_link = \Drupal::l($entity->getTitle(), $url);
    
    +++ b/core/modules/shortcut/src/Form/ShortcutEditForm.php
    @@ -0,0 +1,36 @@
    +      $view_link = \Drupal::l($entity->getTitle(), $url);
    

    use of l is deprecated let's use $this->getLinkGenerator()->generate() instead.

  2. +++ b/core/modules/shortcut/src/Form/ShortcutAddForm.php
    @@ -0,0 +1,36 @@
    +    $message = $this->t('Added a shortcut for @title.', ['@title' => $view_link]);
    +    drupal_set_message($message);
    
    +++ b/core/modules/shortcut/src/Form/ShortcutEditForm.php
    @@ -0,0 +1,36 @@
    +    $message = $this->t('The shortcut @link has been updated.', ['@link' => $view_link]);
    +    drupal_set_message($message);
    

    Let's remove $message variable.

dev.patrick’s picture

@jibran, Adding suggested correction 1 & 2. However for interdiff if I get it correct I need to provide interdiff b/w #39 & #46.

But #39 seems to be corrupt, could you please guide? Really appreciate your guidance on it.

jibran’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs change record

Thanks for updating the patch. @dev.patrick you can create an interdiff from #42 in #44 also you can create interdiff for #46 form #44.

I have created the change notice https://www.drupal.org/node/2920117.

dev.patrick’s picture

@jibran, thanks for reviewing, uploaded both interdiff as asked.

dev.patrick’s picture

Hmm, am doing lots of mistakes :( Appreciate your time for correcting and guiding.

xjm’s picture

Let's deprecate the old class rather than removing it, per https://www.drupal.org/core/deprecation#internal. (This is what #30, #33, #34 above are discussing.) Thanks!

xjm’s picture

Status: Reviewed & tested by the community » Needs work

For #51.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.