Problem/Motivation
The form hooks for entity type and bundles can cause a naming collision if the bundle is named 'type'.
Example:
After installing a new Drupal 8.8.x, I created a content type with the machine name type
When I tried to add content to the above content type I received WSOD.
In the error log, this is the message
Error: Call to undefined method Drupal\node\Entity\Node::getThirdPartySetting() in menu_ui_form_node_type_form_alter() (line 376 of /srv/bindings/3bbcd18b06c44304aea5aca03069c666/code/web/core/modules/menu_ui/menu_ui.module) #0 /srv/bindings/3bbcd18b06c44304aea5aca03069c666/code/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(539): menu_ui_form_node_type_form_alter(Array, Object(Drupal\Core\Form\FormState), 'node_type_form') #1 /srv/bindings/3bbcd18b06c44304aea5aca03069c666/code/web/core/lib/Drupal/Core/Form/FormBuilder.php(835): Drupal\Core\Extension\ModuleHandler->alter('form', Array, Object(Drupal\Core\Form\FormState), 'node_type_form') #2 /srv/bindings/3bbcd18b06c44304aea5aca03069c666/code/web/modules/contrib/devel/webprofiler/src/Form/FormBuilderWrapper.php(29): Drupal\Core\Form\FormBuilder->prepareForm('node_type_form', Array, Object(Drupal\Core\Form\FormState)) #3 /srv/bindings/3bbcd18b06c44304aea5aca03069c666/code/web/core/lib/Drupal/Core/Form/FormBuilder.php(277): Drupal\webprofiler\Form\FormBuilderWrapper->prepareForm('node_type_form', Array, Object(Drupal\Core\Form\FormState)) #4 /srv/bindings/3bbcd18b06c44304aea5aca03069c666/code/web/core/lib/Drupal/Core/Entity/EntityFormBuilder.php(61): Drupal\Core\Form\FormBuilder->buildForm('node_type_form', Object(Drupal\Core\Form\FormState)) #5 /srv/bindings/3bbcd18b06c44304aea5aca03069c666/code/web/core/modules/node/src/Controller/NodeController.php(129): Drupal\Core\Entity\EntityFormBuilder->getForm(Object(Drupal\node\Entity\Node)) #6 [internal function]: Drupal\node\Controller\NodeController->add(Object(Drupal\node\Entity\NodeType)) #7 /srv/bindings/3bbcd18b06c44304aea5aca03069c666/code/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array) #8 /srv/bindings/3bbcd18b06c44304aea5aca03069c666/code/web/core/lib/Drupal/Core/Render/Renderer.php(582): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() #9 /srv/bindings/3bbcd18b06c44304aea5aca03069c666/code/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure)) #10 /srv/bindings/3bbcd18b06c44304aea5aca03069c666/code/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) #11 /srv/bindings/3bbcd18b06c44304aea5aca03069c666/code/vendor/symfony/http-kernel/HttpKernel.php(151): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() #12 /srv/bindings/3bbcd18b06c44304aea5aca03069c666/code/vendor/symfony/http-kernel/HttpKernel.php(68): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1) #13 /srv/bindings/3bbcd18b06c44304aea5aca03069c666/code/web/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #14 /srv/bindings/3bbcd18b06c44304aea5aca03069c666/code/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #15 /srv/bindings/3bbcd18b06c44304aea5aca03069c666/code/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #16 /srv/bindings/3bbcd18b06c44304aea5aca03069c666/code/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true) #17 /srv/bindings/3bbcd18b06c44304aea5aca03069c666/code/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #18 /srv/bindings/3bbcd18b06c44304aea5aca03069c666/code/web/modules/contrib/devel/webprofiler/src/StackMiddleware/WebprofilerMiddleware.php(38): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #19 /srv/bindings/3bbcd18b06c44304aea5aca03069c666/code/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(52): Drupal\webprofiler\StackMiddleware\WebprofilerMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #20 /srv/bindings/3bbcd18b06c44304aea5aca03069c666/code/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #21 /srv/bindings/3bbcd18b06c44304aea5aca03069c666/code/web/core/lib/Drupal/Core/DrupalKernel.php(693): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #22 /srv/bindings/3bbcd18b06c44304aea5aca03069c666/code/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request)) #23 {main}.
Proposed resolution
Steps to replicate
- Install a new Drupal 8.8.x
- Create content type with machine name
type
- Create new content of the content type
type
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Comments
Comment #2
sjshaalComment #3
shaalI can confirm that bug exist.
I was able to replicate it by following the steps suggested.
Comment #5
johnwebdev commentedThis is happening because of naming collision.
For entity forms the form Id is constructed by:
Entity type Id
Bundle (if applicable)
Operation (if operation is default, it does not append)
Menu UI module alters the node type (content type) form, and since your content type is called 'type' that hook will kick in.
This could also potentially happen to Media, if you were to add a bundle called 'type'.
Comment #6
johnwebdev commentedComment #7
berdirWell, this is ugly.
There's not much we can do about the form id conflict, so the only non-crazy-complex solution might be to disallow creating an entity type with that name?
Comment #8
fcobbaert commentedI have added a check to disallow the creation of a content type named 'type'. As johndevman suggested this could also be an issue if you were to create a media type, I checked this but it doesn't seem to be an issue there.
Comment #9
berdirWell, it's not an immediate error, but the conflict exists there as well.
Comment #10
johnwebdev commentedI am wondering if doing this change on the entity form is enough, if entity bundles may be created through i.e. JSON:API or REST this would be bypassed(?)
Maybe a entity constraint?
Comment #18
cleverhoods commentedAs mentioned by @johnwebdev above, the issue was a name collision.
Added a check to make sure the code operates with the expected instance.
Comment #19
anandhi karnan commentedI have tested the provided patch #18 and can confirm that it resolves the issue as described. The problem no longer occurs in Drupal 11.x
Thank you for the patch!
Comment #20
tolstoydotcomIsn't this a case of "it hurts when I do that/so stop doing that"? I don't know if it's still an issue, but having a theme and a module with the same machine name also resulted in conflicts. Is there a check for that now? Not everything can be checked.
Maybe this could just be put into documentation.