Operation is null in custom menu link form

Created on 22 May 2023, over 1 year ago
Updated 13 June 2024, 4 months ago

Problem/Motivation

In 🐛 Save menu link redirects to another URL, causing access denied Fixed 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 📌 TypeError: Argument 1 passed to Drupal\simple_sitemap\Form\Handler\EntityFormHandlerBase::isSupportedOperation() must be of the type string, null given Closed: works as designed
Use simple simteap 4.X
Edit group menu link (on dev where 🐛 Save menu link redirects to another URL, causing access denied Fixed 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.

🐛 Bug report
Status

Fixed

Version

3.0

Component

Code

Created by

🇧🇪Belgium mallezie Loenhout

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024