0
votes

I am facing a very strange problem while trying to override a custom content type edit form template in my custom theme.

I have a custom theme mysite_admin (sub-theme of seven) with a minimal setup. It has mandatory mysite_admin.info.yml and mysite_admin.theme file. I created a content type named Very Basic Content Type for demonstration purposes. Now I want to preprocess the edit form for said content type so I create a following function in mysite_admin.theme file

function mysite_admin_preprocess_form__node_very_basic_content_type_form(&$variables) {
    ksm($variables);
}

flush cashes, and instead of seeing the variables output on top of my edit form I see an exception as follows

The website encountered an unexpected error. Please try again later.
TypeError: Argument 1 passed to Drupal\Core\Render\Element::setAttributes() must be of the type array, null given, called in /home/ejaz/sites/mysite/core/includes/form.inc on line 362 in Drupal\Core\Render\Element::setAttributes() (line 173 of core/lib/Drupal/Core/Render/Element.php).

Drupal\Core\Render\Element::setAttributes() (Line: 362)
template_preprocess_form() (Line: 287)
Drupal\Core\Theme\ThemeManager->render() (Line: 431)
Drupal\Core\Render\Renderer->doRender() (Line: 200)
Drupal\Core\Render\Renderer->render() (Line: 226)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 573)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 227)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare() (Line: 117)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse() (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray()
call_user_func() (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch() (Line: 156)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 68)
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: 694)
Drupal\Core\DrupalKernel->handle() (Line: 19)

I see the same exception if I create a template named form--node-very-basic-content-type-form.html.twig in my custom theme's templates directory while not having said preprocess function in theme file.

Wagwan?

1

1 Answers

0
votes

Use hook_form_alter instead and play with it by adding condition specific to your content edit form.