From 4cbd423b9c536d8547b595dfc1889e3bde64bca3 Mon Sep 17 00:00:00 2001 From: Kristen Pol Date: Fri, 31 Jan 2025 13:37:24 -0800 Subject: [PATCH] Add a warning if a webform is on the page. --- quant.module | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/quant.module b/quant.module index f827a82..bdb32e6 100644 --- a/quant.module +++ b/quant.module @@ -6,6 +6,7 @@ */ use Drupal\Core\Access\AccessResult; +use Drupal\Core\Entity\Display\EntityViewDisplayInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Session\AccountInterface; @@ -520,3 +521,26 @@ function quant_preprocess_views_view(array &$variables) { } } + +/** + * Implements hook_node_view(). + */ +function quant_node_view(array &$build, EntityInterface $node, EntityViewDisplayInterface $display, $view_mode) { + + // If there are any webforms in layout_builder, add warning for admins. + if ($node->hasField('layout_builder__layout') && !$node->get('layout_builder__layout')->isEmpty()) { + $sections = $node->get('layout_builder__layout')->getSections(); + + foreach ($sections as $section) { + $components = $section->getComponents(); + + foreach ($components as $component) { + $configuration = $component->get('configuration'); + if (isset($configuration['webform_id'])) { + \Drupal::messenger()->addWarning(t('Forms need special handling for a static website. See the documentation for your options.')); + return; + } + } + } + } +}