drupal_entity_form throws error when trying to use alternate form_mode

Created on 16 September 2021, over 3 years ago
Updated 24 June 2023, over 1 year ago

Problem/Motivation

Trying to use drupal_entity_form to display a non-default form causes error.

Tried debugging and changing the form_mode default value in /src/TwigTweakExtension.php - no change.

Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException: The "node" entity type did not specify a "node.front_end_form" form class. in Drupal\Core\Entity\EntityTypeManager->getFormObject() (line 223 of core/lib/Drupal/Core/Entity/EntityTypeManager.php).

Drupal\Core\Entity\EntityFormBuilder->getForm() (Line: 49)
Drupal\twig_tweak\View\EntityFormViewBuilder->build() (Line: 187)
Drupal\twig_tweak\TwigTweakExtension::drupalEntityForm() (Line: 54)
__TwigTemplate_af2f486cf46791750e7f9addfd846ee9874f25889c8ace47aedf947199224610->doDisplay() (Line: 405)
Twig\Template->displayWithErrorHandling() (Line: 378)
Twig\Template->display() (Line: 219)
__TwigTemplate_5124edd36129f6cd9b490666d9649d67cc9dc5c26b784c483bf1dc529cc774bb->doDisplay() (Line: 405)
Twig\Template->displayWithErrorHandling() (Line: 378)
Twig\Template->display() (Line: 390)
Twig\Template->render() (Line: 65)
twig_render_template() (Line: 384)
Drupal\Core\Theme\ThemeManager->render() (Line: 431)
Drupal\Core\Render\Renderer->doRender() (Line: 200)
Drupal\Core\Render\Renderer->render() (Line: 241)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 573)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 242)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare() (Line: 132)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse() (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray()
call_user_func() (Line: 142)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch() (Line: 163)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 80)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 57)
Drupal\Core\StackMiddleware\Session->handle() (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 23)
Stack\StackedHttpKernel->handle() (Line: 706)
Drupal\Core\DrupalKernel->handle() (Line: 19)

Steps to reproduce

1. Make a new content Form Mode:

/admin/structure/display-modes/form

2. Activate the new form display on a content type:

/admin/structure/types/manage/sighting/form-display - Custom Display Types

3. Add fields to the new form mode for the content type:

/admin/structure/types/manage/sighting/form-display/front_end_form

4. In twig template, call for the add node form:

{{ drupal_entity_form('node', null, 'node.front_end_form', values={type: 'sighting'} ) }}

💬 Support request
Status

Closed: works as designed

Version

3.1

Component

Code

Created by

🇬🇧United Kingdom FlusteredLondon

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.

  • 🇩🇪Germany bennos

    this works
    {{ drupal_entity_form('node', null, 'front_end_form', values={type: 'sighting'} ) }}

    After you have added the form mode, you need a drush cr and make clear that the form mode is registered.

    "'node.front_end_form'"
    is wrong because you already define the entity type with "node". For the form mode just use maschine name here "front_end_form".

Production build 0.71.5 2024