Problem/Motivation

ViewsUI::getStandardButtons() has some magic to find cancel submit handler. It looks for functions with the same name as the form ID, with the suffix _cancel.

The code looks like this, and has existed since at least views 6.x-2.x in contrib.

$cancel_submit = function_exists($form_id . '_cancel') ? $form_id . '_cancel' : [$this, 'standardCancel'];

But this is a relic to a time when forms exists in procedural functions in the global namespace. Forms now belong in their own classes, with submit handlers bundled in to the class. There are no _cancel() functions left in core that are associated with forms.

There is a possibility existing contrib or custom modules are relying on this behaviour, but if these functions exist in .module files, they will stop working once .module files are deprecated and removed. By deprecating now these can be updated to manually specify the submit handlers in the form class.

Steps to reproduce

$ grep -r "function .*_cancel(" core
core/modules/user/user.api.php:function hook_user_cancel($edit, UserInterface $account, $method): void {
core/modules/user/user.module:function user_cancel($edit, $uid, $method): void {
core/modules/user/user.module:function _user_cancel($edit, $account, $method): void {

Proposed resolution

Refactor $cancel_submit to throw a deprecation if the function_exists call finds something.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-3536204

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

mstrelan created an issue. See original summary.

mstrelan’s picture

Status: Active » Needs work
Issue tags: +Needs change record

Did the deprecation, needs a change record. Could possibly do a deprecation test but it would involve adding a test module with a form that calls $view->getStandardButtons similar to \Drupal\views_ui\Form\Ajax\ReorderDisplays and also declare a function with the magic naming convention.

voleger’s picture

mstrelan’s picture

I don't think that issue is related. The grep in the summary is showing that there are no _cancel functions related to views forms. The ones remaining are for the hook, which is what the related issue is about. I can see how that has led to confusion though.

nicxvan’s picture

This needs a CR and the deprecation needs to be updated with the correct CR.

Deprecations don't need a test, the rest of the MR does look good.

I removed the unrelated issue.

mstrelan’s picture

Agree we don't normally need a test for a deprecation, unless it's a weird implementation. I think what I really meant that we don't actually have any evidence that the behaviour we're deprecating even works in the first place, so we could test for that as a deprecation test. But I don't know if it's worth it.

catch’s picture

It feels very unlikely that anyone is relying on this, and fairly unlikely that it even works at all, so for me fine to skip deprecation test coverage here.

nicxvan’s picture

Great thanks! I created a CR and added a suggestion to change the deprecation to use the CR.

It could use a pass.

mstrelan’s picture

Status: Needs work » Needs review
Issue tags: -Needs change record

Applied the suggestion from the MR and updated the CR to make it specific to Views UI and with a more realistic example.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new1.29 KB

The Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

mstrelan’s picture

Status: Needs work » Needs review
nicxvan’s picture

Status: Needs review » Reviewed & tested by the community

Huh it seemsmy comment was eaten but you got my suggestions anyway.

CR is far better now thanks!

Deprecation is correct now too.

Good to go.

xjm’s picture

Title: Deprecate magic cancel submit handlers in views ui » Deprecate magic cancel submit handlers in Views UI
Issue summary: View changes
Status: Reviewed & tested by the community » Needs review
Issue tags: +Needs subsystem maintainer review

Nice find. This is an excellent cleanup, but we should probably have subsystem maintainer signoff to ensure we're not leaving behind any trailing related bits etc. I'm technically only a maintainer for Views, not Views UI, so bumping back to NR. I'll also ping Lendude.

xjm’s picture

We might want to target Drupal 13 for this deprecation. I tried to search contrib to see if this was widely used still, but ran into problems with the fuzziness (it refusing to do an exact search for _cancel().

lendude’s picture

Can't think of (or find) anything either that could possibly rely on this. So great clean up as far as I can tell.

mstrelan’s picture

So is this RTBC or need to be updated for D13? It seems incredibly niche.

xjm’s picture

I agree that it does seem very niche, but since it is a very dynamic public API that could be used in a lot of ways and I couldn't get a good sense of how many might still exist from the contrib search, I think I'd still deprecate it for Drupal 13 to be safe. .module files themselves aren't going to be removed before then, either, so it shouldn't be problematic to keep them around the extra two years. Thanks @mstrelan!

mstrelan’s picture

I tried to search contrib to see if this was widely used still, but ran into problems with the fuzziness (it refusing to do an exact search for _cancel().

Apparently this is a known issue - https://git.drupalcode.org/help/user/search/advanced_search.md#known-issues

The search query must not contain any of the following characters:
. , : ; / ` ' = ? $ & ^ | < > ( ) { } [ ] @

So perhaps http://codcontrib.hank.vps-private.net/search?text=_cancel%28&filename= is a better way to search.

Bumped removed version to 13.

nicxvan’s picture

Status: Needs review » Reviewed & tested by the community

We got sign off from the subsystem maintainer and bumped the removed version.

Good to go!

xjm’s picture

The main problem with the search was actually not being able to get a string literal match for the underscore, even when I dropped the parenthesis. But anyway, it's fine with a D13 deprecation and @lendude's signoff. Thanks!

I made a couple small fixes to the CR and fixed a broken link in the MR.

  • xjm committed d7daf56f on 11.x
    Issue #3536204 by mstrelan, xjm, nicxvan, catch, lendude: Deprecate...
xjm’s picture

Status: Reviewed & tested by the community » Fixed

Committed to 11.x and published the change record. Thanks!

Status: Fixed » Closed (fixed)

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