Problem/Motivation

this error shows up when using the entity browser to select an image for an image field

Steps to reproduce

addf an image field to a node, enable rabbit hole, use the entity browser to select an image when creating a new node.

Proposed resolution

use this patch

Remaining tasks

patch is attached

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

hazuzoo created an issue. See original summary.

keshavv’s picture

Status: Active » Needs review
nsciacca’s picture

I got a similar error with Views Bulk Operations:

Error: Call to undefined method Drupal\views_bulk_operations\Form\ConfigureAction::getEntity() in Drupal\rabbit_hole\Plugin\Field\FieldWidget\RabbitHoleDefaultWidget->formElement() (line 168 of modules/contrib/rabbit_hole/src/Plugin/Field/FieldWidget/RabbitHoleDefaultWidget.php).

Adding the below check to the top of the formElement function works for my instance.

if (!method_exists($form_state->getFormObject(), 'getEntity')) {
   return;
}
ayush.pandey’s picture

Hi, the issue seems to not reproducible. I tried the module version 2.0.0-alpha5 with drupal 10.1 and the node gets saved successfully with the media entity. Please check once, and add complete steps if its still reproducible .

karimbou’s picture

Having this issue on production Drupal 9.5.x and rabbit_hole 2.0.0-alpha5
Creating a new article and trying to open entity browser through a paragraph (popup entity browser show the error)

The website encountered an unexpected error. Please try again later.
Error: Call to undefined method Drupal\entity_browser\Form\EntityBrowserForm::getEntity() in Drupal\rabbit_hole\Plugin\Field\FieldWidget\RabbitHoleDefaultWidget->formElement() (line 151 of modules/contrib/rabbit_hole/src/Plugin/Field/FieldWidget/RabbitHoleDefaultWidget.php).
Drupal\rabbit_hole\Plugin\Field\FieldWidget\RabbitHoleDefaultWidget->formElement(Object, 0, Array, Array, Object) (Line: 353)
Drupal\Core\Field\WidgetBase->formSingleElement(Object, 0, Array, Array, Object) (Line: 220)
Drupal\Core\Field\WidgetBase->formMultipleElements(Object, Array, Object) (Line: 111)
Drupal\Core\Field\WidgetBase->form(Object, Array, Object) (Line: 183)
Drupal\Core\Entity\Entity\EntityFormDisplay->buildForm(Object, Array, Object) (Line: 190)
Drupal\inline_entity_form\Form\EntityInlineForm->entityForm(Array, Object) (Line: 152)
Drupal\inline_entity_form\Element\InlineEntityForm::processEntityForm(Array, Object, Array)
call_user_func_array(Array, Array) (Line: 1012)
Drupal\Core\Form\FormBuilder->doBuildForm('entity_browser_entity_browser_images_form', Array, Object) (Line: 1075)
Drupal\Core\Form\FormBuilder->doBuildForm('entity_browser_entity_browser_images_form', Array, Object) (Line: 1075)
Drupal\Core\Form\FormBuilder->doBuildForm('entity_browser_entity_browser_images_form', Array, Object) (Line: 579)
Drupal\Core\Form\FormBuilder->processForm('entity_browser_entity_browser_images_form', Array, Object) (Line: 325)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
Drupal\Core\Controller\FormController->getContentResult(Object, 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: 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)

karimbou’s picture

StatusFileSize
new1.15 KB

To avoid some warnings on $form['#type'] array key, that might not exist i've added an isset to the patch.

alexdoma’s picture

StatusFileSize
new1.47 KB

patch #6 now working for me
i have get code from https://www.drupal.org/project/hide_revision_field module and its helps for me
drupal 10.1.3

julianvj’s picture

Not able to reproduce this issue on Drupal 10.1.9 with RabiitHole 2.0.0-alpha5 and Entity Browser 2.10.
This seems to be a very special use case or applicable onty to Drupal 9

philip_stier’s picture

I was also getting this exact same error with Entity Browser. #6 worked for me. Drupal 10.1.7

interdruper’s picture

Status: Needs review » Reviewed & tested by the community
Related issues: +#3383171: Error: Call to undefined method Drupal\entity_browser\Form\EntityBrowserForm::getEntity()

Both #6 and #7 fix the problem. Thanks.

andreasderijcke’s picture

Still a problem for 2.0.0-alpha5 in combination with

  1. core 10.3.x
  2. views_bulk_operations 4.2.7 (i know it's not the recommended version anymore)

The error only appears in this combination when you try to bulk edit nodes that allow rabbit hole overrides.

greg boggs’s picture

After applying #6 in Drupal 10.3, I get a new error when applying a modify data VBO action.

Error: Call to a member function getEntityTypeId() on null in Drupal\rabbit_hole\Plugin\Field\FieldWidget\RabbitHoleDefaultWidget->formElement() (line 166 of modules/contrib/rabbit_hole/src/Plugin/Field/FieldWidget/RabbitHoleDefaultWidget.php).

greg boggs’s picture

Status: Reviewed & tested by the community » Needs work
nicodh’s picture

Status: Needs work » Needs review

#7 works for me in #13 use case

oriol_e9g’s picture

StatusFileSize
new1.47 KB

Reroll.

damienmckenna’s picture

Version: 2.0.0-alpha5 » 2.0.x-dev
Assigned: hazuzoo » Unassigned
ishani patel’s picture

Facing the same issue, and applying the #7 patch worked for me.
Thanks!

anybody’s picture

Priority: Minor » Normal

Could someone please create a MR from the patch? Doesn't sound minor to me.

coulton’s picture

Applied Patch #7 which has worked for me. On Drupal 11.3.8

rcodina made their first commit to this issue’s fork.

rcodina’s picture

@anybody Patch on #16 works for me on Drupal 11.3.16 and Rabbit Hole 2.0.0-beta2. So I have created a MR using it.

rcodina’s picture

Following up on my previous comment: the pipeline on the MR is red, but I do not think the patch in #16 is the cause.

Only phpunit actually blocks. phpcs, phpstan and eslint are allow_failure: true, and they were already failing in the last green 2.0.x pipeline (pipeline 759534, March 2026).

The 7 phpunit errors are all the same one, and they all happen in setUp(): a LogicException: Missing bundle entity, entity type node_type, entity id article. thrown from src/Entity/BehaviorSettings.php:245. Both test classes use the standard profile and then save a BehaviorSettings for node.article. Since Drupal 11.4 the Standard profile no longer ships the Article content type — core/profiles/standard/config/install/node.type.article.yml is there in 11.2.0 and 11.3.0, but gone in 11.4.5, which is what the pipeline installs — so calculateDependencies() throws. The patch only touches formElement(), which is never reached in those tests.

I did tidy the patch slightly in the MR, hopefully in the spirit of the original: elseif/else on their own lines (removes the 3 new phpcs errors it added), plus a ?? $items->getEntity() fallback in the container branch so $entity is always defined.

The test failure probably deserves a separate issue, something like "Functional tests fail on Drupal 11.4: the Standard profile no longer provides the Article content type"; the fix would likely be creating the bundle in setUp() with $this->drupalCreateContentType(['type' => 'article']) instead of relying on the profile. I will not be able to work on that one myself, but happy to test a patch if someone picks it up.

The failing traces, for reference:

LogicException: Missing bundle entity, entity type node_type, entity id article.
  src/Entity/BehaviorSettings.php:245
  tests/src/Functional/RabbitHolePageRedirectActionTest.php:54
  tests/src/Functional/RabbitHoleBehaviorFunctionalTest.php:50
rcodina’s picture

Follow-up on the pipeline: the phpunit failures are unrelated to this patch. The root cause is core #3587118: Remove content types from the standard install profile and recipe, which removed the content types from the Standard install profile in 11.4, so the two Functional tests that declare $profile = 'standard' no longer get the Article bundle they save Rabbit Hole settings for. They error in setUp(), before any of the code this issue touches runs.

It was already fixed on 8.x-1.x by Jakob P in merge request 117 (commit a9e6f362), but 2.0.x has not had it yet. I have applied the same guard here, in both RabbitHolePageRedirectActionTest::setUp() and RabbitHoleBehaviorFunctionalTest::setUp():

// As of Drupal 11.4 the Standard profile no longer provides the "Article"
// content type.
if (!NodeType::load('article')) {
  $this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']);
}

It is in its own commit, so it is easy to drop if you would rather see the test fix handled on its own — #3576742: Fix PHPUnit tests on 8.x-1.x was closed with a note about moving to 2.0.x for the rest, so it may already be on its way. It should get the Functional tests past setUp() at least; what happens after that has never actually run on 11.4 on this branch, so there may be more to fix.