From 8936fdbb06dc99a86f6145a034710b3935316fcb Mon Sep 17 00:00:00 2001
From: Eric Bremner <ebremner@uwaterloo.ca>
Date: Fri, 14 Oct 2022 10:02:54 -0400
Subject: [PATCH] ISTWCMS-5880: adding code to remove hero image from media for
 certain content types

---
 uw_cfg_common.module | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/uw_cfg_common.module b/uw_cfg_common.module
index 4843c0f7..3b252cca 100644
--- a/uw_cfg_common.module
+++ b/uw_cfg_common.module
@@ -893,14 +893,17 @@ function uw_cfg_common_form_alter(array &$form, FormStateInterface $form_state,
   // actual media types in the hero section.
   if (isset($form['field_uw_type_of_media'])) {
 
-    $node_type = str_replace('node_uw_ct_', '' , $form_id);
-    $node_type = str_replace('_edit', '' , $node_type);
-    $node_type = str_replace('_form', '' , $node_type);
+    // Get the node type from the form id.
+    $node_type = str_replace('node_uw_ct_', '', $form_id);
+    $node_type = str_replace('_edit', '', $node_type);
+    $node_type = str_replace('_form', '', $node_type);
 
+    // Content types to remove the hero image from media.
     $remove_hero_image_nodes = [
       'web_page',
     ];
 
+    // If the node type can not have hero image, remove the option.
     if (in_array($node_type, $remove_hero_image_nodes)) {
       unset($form['field_uw_type_of_media']['widget']['#options']['image']);
     }
-- 
GitLab