Problem/Motivation
When loading an asset that doesn't exist (in my case a *.css.map file) and if the Drupal-bootstrapped 404 page renders a webform block by using some instructions like the sample below:
if ($inline_webform) {
$webform_id = $config->get('settings.webform_id');
$webform = \Drupal::entityTypeManager()->getStorage('webform')->load($webform_id);
$view_builder = \Drupal::service('entity_type.manager')->getViewBuilder('webform');
$build = $view_builder->view($webform);
return [
'#theme' => 'gcweb-inline-webform',
'#content' => $build,
];
}
I get a PHP deprecation warning:
Deprecated function: preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in webform_form_alter() (line 35 of /var/www/html/html/modules/contrib/webform/includes/webform.form_alter.inc)
#0 /var/www/html/html/core/includes/bootstrap.inc(164): _drupal_error_handler_real(8192, 'preg_match(): P...', '/var/www/html/h...', 35)
#1 [internal function]: _drupal_error_handler(8192, 'preg_match(): P...', '/var/www/html/h...', 35)
#2 /var/www/html/html/modules/contrib/webform/includes/webform.form_alter.inc(35): preg_match('/^entity.webfor...', NULL)
#3 /var/www/html/html/core/lib/Drupal/Core/Extension/ModuleHandler.php(545): webform_form_alter(Array, Object(Drupal\Core\Form\FormState), 'webform_submiss...')
#4 /var/www/html/html/core/lib/Drupal/Core/Form/FormBuilder.php(841): Drupal\Core\Extension\ModuleHandler->alter('form', Array, Object(Drupal\Core\Form\FormState), 'webform_submiss...')
#5 /var/www/html/html/core/lib/Drupal/Core/Form/FormBuilder.php(284): Drupal\Core\Form\FormBuilder->prepareForm('webform_submiss...', Array, Object(Drupal\Core\Form\FormState))
#6 /var/www/html/html/core/lib/Drupal/Core/Entity/EntityFormBuilder.php(48): Drupal\Core\Form\FormBuilder->buildForm(Object(Drupal\webform\WebformSubmissionForm), Object(Drupal\Core\Form\FormState))
#7 /var/www/html/html/modules/contrib/webform/src/Entity/Webform.php(1257): Drupal\Core\Entity\EntityFormBuilder->getForm(Object(Drupal\webform\Entity\WebformSubmission), 'add')
#8 /var/www/html/html/modules/contrib/webform/src/WebformEntityViewBuilder.php(18): Drupal\webform\Entity\Webform->getSubmissionForm()
#9 /var/www/html/html/profiles/wxt/modules/custom/wxt_ext/wxt_ext_webform/src/Plugin/Block/ReportProblemBlock.php(137): Drupal\webform\WebformEntityViewBuilder->view(Object(Drupal\webform\Entity\Webform))
#10 /var/www/html/html/core/modules/block/src/BlockViewBuilder.php(171): Drupal\wxt_ext_webform\Plugin\Block\ReportProblemBlock->build()
Steps to reproduce
- Make sure that your instance runs PHP 8.1+
- Create a plugin block and and render a webform in it (look for the code snippet above)
- place the block in the 404 page
- Load an asset that doesn't exists (could be a map|xls|docx file, just make sure that you'll get the bootstrapped 404 page instead of the webserver html-generated response) you should get a warning after that:
Proposed resolution
At a condition in the file webform.form_alter.inc
(at line 35) to check if the call to \Drupal::routeMatch()->getRouteName()
will return an actual route name:
// Display editing original language warning.
if (\Drupal::moduleHandler()->moduleExists('config_translation') && preg_match('/^entity.webform.(?:edit|settings|assets|access|handlers|third_party_settings)_form$/', \Drupal::routeMatch()->getRouteName())) {
/** @var \Drupal\webform\WebformInterface $webform */
$webform = \Drupal::routeMatch()->getParameter('webform');
/** @var \Drupal\Core\Language\LanguageManagerInterface $language_manager */
$language_manager = \Drupal::service('language_manager');
Remaining tasks
User interface changes
API changes
Data model changes