Problem/Motivation

In #3342780: Save menu link redirects to another URL, causing access denied custom forms where introduced for menu link entities.
There it can happen the $operation on the form object becomes null.

Before we used the default entityform builder, which defined default operations.
See Core EntityFormBuilder class
public function getForm(EntityInterface $entity, $operation = 'default', array $form_state_additions = [])

In the getForm method in our controller this is not taken into account.
https://git.drupalcode.org/project/group_content_menu/-/blob/8.x-1.x/src...

Steps to reproduce

Simple_sitemap 4.x requires the operation (because core requires it). See https://www.drupal.org/project/simple_sitemap/issues/3292346
Use simple simteap 4.X
Edit group menu link (on dev where #3342780: Save menu link redirects to another URL, causing access denied is in).
It breaks on the edit page.

The website encountered an unexpected error. Please try again later.
TypeError: Drupal\simple_sitemap\Form\Handler\EntityFormHandlerBase::isSupportedOperation(): Argument #1 ($operation) must be of type string, null given, called in /var/www/html/docroot/modules/contrib/simple_sitemap/src/Form/FormHelper.php on line 127 in Drupal\simple_sitemap\Form\Handler\EntityFormHandlerBase->isSupportedOperation() (line 209 of modules/contrib/simple_sitemap/src/Form/Handler/EntityFormHandlerBase.php).
Drupal\simple_sitemap\Form\Handler\EntityFormHandlerBase->isSupportedOperation(NULL) (Line: 127)
Drupal\simple_sitemap\Form\FormHelper->formAlter(Array, Object) (Line: 42)
simple_sitemap_form_alter(Array, Object, 'menu_link_content_menu_link_content__form') (Line: 562)
Drupal\Core\Extension\ModuleHandler->alter('form', Array, Object, 'menu_link_content_menu_link_content__form') (Line: 840)
Drupal\Core\Form\FormBuilder->prepareForm('menu_link_content_menu_link_content__form', Array, Object) (Line: 284)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 181)
Drupal\group_content_menu\Controller\GroupContentMenuController->getForm('Drupal\group_content_menu\Form\MenuLinkItemForm', Object) (Line: 141)
Drupal\group_content_menu\Controller\GroupContentMenuController->editLink(Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 580)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 169)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 81)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 49)
Asm89\Stack\Cors->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 718)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Proposed resolution

Add the operation back as the default content entity form does.

Comments

mallezie created an issue. See original summary.

mallezie’s picture

Status: Active » Needs review
StatusFileSize
new1.04 KB
heddn’s picture

This seems very edge case. Can we add a test for it in any way? I'm drawing a blank about how, but hopeful that you can think of someway.

zeip’s picture

The patch in #2 worked for us, thanks!

a.dmitriiev’s picture

StatusFileSize
new1.04 KB

The same problem exists in version 3.0.x. Attaching the patch for it as well.

heddn’s picture

Version: 8.x-1.x-dev » 3.0.x-dev
Status: Needs review » Reviewed & tested by the community

Coincidentally, ran into this bug today on a project. And now I'm not so sure that a test case is possible. Will just commit the change.

  • heddn committed 18174f8a on 3.0.x
    Issue #3361822 by mallezie, heddn: Operation is null in custom menu link...

  • heddn committed fa3a94cd on 2.0.x
    Issue #3361822 by mallezie, heddn: Operation is null in custom menu link...
heddn’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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