Skip to content

Commit fd296b0

Browse files
authored
Merge pull request #246 from quantcdn/feature/webform-warning
Add a warning if a webform is on the page.
2 parents 7c9f6d4 + 6ac1d7b commit fd296b0

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

quant.module

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77

88
use Drupal\Core\Access\AccessResult;
9+
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
910
use Drupal\Core\Entity\EntityInterface;
1011
use Drupal\Core\Form\FormStateInterface;
1112
use Drupal\Core\Session\AccountInterface;
@@ -520,3 +521,26 @@ function quant_preprocess_views_view(array &$variables) {
520521
}
521522

522523
}
524+
525+
/**
526+
* Implements hook_node_view().
527+
*/
528+
function quant_node_view(array &$build, EntityInterface $node, EntityViewDisplayInterface $display, $view_mode) {
529+
530+
// If there are any webforms in layout_builder, add warning for admins.
531+
if ($node->hasField('layout_builder__layout') && !$node->get('layout_builder__layout')->isEmpty() && \Drupal::currentUser()->hasRole('administrator')) {
532+
$sections = $node->get('layout_builder__layout')->getSections();
533+
534+
foreach ($sections as $section) {
535+
$components = $section->getComponents();
536+
537+
foreach ($components as $component) {
538+
$configuration = $component->get('configuration');
539+
if (isset($configuration['webform_id'])) {
540+
\Drupal::messenger()->addWarning(t('Forms need special handling for a static website. <a href="https://docs.quantcdn.io/integrations/drupal">See the documentation for your options</a>.'));
541+
return;
542+
}
543+
}
544+
}
545+
}
546+
}

0 commit comments

Comments
 (0)