TypeError: Argument 1 passed to Drupal\simple_sitemap\Form\Handler\EntityFormHandlerBase::isSupportedOperation() must be of the type string, null given

Created on 23 June 2022, over 2 years ago
Updated 11 September 2024, 3 months ago

Problem/Motivation

I'm working on a site that has some custom entities defined. The FormHelper helper class assumes getOperation returns a result, but I guess in some cases, it may return null. In a few cases, I've seen:

TypeError: Argument 1 passed to
Drupal\simple_sitemap\Form\Handler\EntityFormHandlerBase::isSupportedOperation()
must be of the type string, null given

Proposed resolution

A quick and dirty fix might be more fault tolerant evaluation such as ...

   $form_operation = $form_object->getOperation() ?? false;

    if ($form_handler instanceof EntityFormHandlerInterface && $form_handler->isSupportedOperation($form_operation)) {
      $entity_type_id = $form_handler->getEntityTypeId();
      if ($this->generator->entityManager()->entityTypeIsEnabled($entity_type_id)) {
        $form_handler->formAlter($form, $form_state);
      }
    }

in https://git.drupalcode.org/project/simple_sitemap/-/blob/4.x/src/Form/Fo...

Another option might be to explore options like Rabbit Hole?
https://git.drupalcode.org/project/rabbit_hole/-/blob/8.x-1.x/rabbit_hol...

Remaining tasks

Assess the problem, consider fixes.

User interface changes

TBD - Presumed to be none.

API changes

TBD - Presumed to be none.

Data model changes

TBD - Presumed to be none.

📌 Task
Status

Closed: works as designed

Version

4.0

Component

Code

Created by

🇺🇸United States matt_paz

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇺🇸United States attheshow

    Just reporting that I ran into the same issue here with a custom entity.

  • Status changed to Needs review about 1 year ago
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 8.1 & MySQL 8
    last update about 1 year ago
    32 pass
  • 🇭🇺Hungary imre.horjan Hungary

    Hello,

    f you don't mind I reopen this issue and added a patch for it.

    I can reproduce it using Drupal 10.1, PHP 8.1, while editing a menu item using the Group Content Menu module.
    https://www.drupal.org/project/group_content_menu/

    Even though simple sitemap is enabled only for node and media entities, I get the same error message editing an entity (menu item in this case).
    I think custom entity types can also trigger this error, which prevent editing them.

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.4 + Environment: PHP 8.1 & MySQL 8
    last update about 1 year ago
    32 pass
  • First commit to issue fork.
  • 🇫🇮Finland ZeiP

    We were also experiencing this after D10.1 upgrade. For us it seems to be caused and fixed by 🐛 Operation is null in custom menu link form Needs review . The patch also did fix it though.

  • Status changed to Closed: works as designed about 1 year ago
  • 🇷🇺Russia walkingdexter

    The patch is not needed. If $form_object->getOperation() returns NULL it means that the EntityFormInterface is not implemented correctly.

  • Status changed to RTBC 4 months ago
  • 🇺🇸United States jnicola

    This fixes the same error for me that I experience when deleting group_content_menu items.

    I don't think it would be criminal to consider making the code here a bit more tolerant, especially since in it's tolerance everything is hunky dory.

  • Status changed to Closed: works as designed 3 months ago
  • 🇺🇸United States jnicola

    @walkingdexter could you explain your resistance or what the issue would be in implementing this bit of code?

    I don't think it's fair to say that getOperation() returning NULL is a third party problem, since getOperation does not specify return types.

  • 🇷🇺Russia walkingdexter

    I don't think it's fair to say that getOperation() returning NULL is a third party problem, since getOperation does not specify return types.

    @jnicola The return type is specified in PHPDoc, which is respected by PHPStan.

  • 🇺🇸United States jnicola

    Eh, I suppose. I wonder just how much of Drupal would need to be redocumented or fixed once return types are specified and discover how much wasn't actually as expected...

    Is there any loss to be had adding a sanity check here besides a milisecond or two of time?

  • 🇷🇺Russia walkingdexter

    Is there any loss to be had adding a sanity check here besides a milisecond or two of time?

    I'm not a fan of adding unnecessary checks that go against the documentation. Incorrect implementation can lead to errors not only with this module. The above case clearly shows that the problem is related to the third party.

  • 🇩🇪Germany gbyte Berlin

    I support walkingdexter on this matter - I do sometimes work around other modules' problems, but those modules better be in core, otherwise this is a never ending endeavour.

Production build 0.71.5 2024