diff --git a/uw_cfg_common.module b/uw_cfg_common.module index cebe39102f0396e4ea27d156d341972f7a98c333..4dd2ca43eaf4996d0d93e7c1c39240beb5f549eb 100644 --- a/uw_cfg_common.module +++ b/uw_cfg_common.module @@ -17,14 +17,22 @@ use Drupal\webform\WebformSubmissionStorageInterface; */ function uw_cfg_common_metatags_alter(array &$metatags, array $context) { - // Get the node entity. - $entity = $context['entity']; - - // If there is no associated image, add the fall back university - // logo to image_src and og_image tags. - if (!$entity->field_uw_meta_image->target_id) { - $metatags['image_src'] = 'https://uwaterloo.ca/university-of-waterloo-logo-152.png'; - $metatags['og_image'] = 'https://uwaterloo.ca/university-of-waterloo-logo-152.png'; + // Get the route match so we can check if this is a node. + $route_match = \Drupal::routeMatch(); + + // If we are on a node, check for associated image and + // set metatag image info appropriately. + if ($route_match->getRouteName() == 'entity.node.canonical') { + + // Get the node entity. + $entity = $context['entity']; + + // If there is no associated image, add the fall back university + // logo to image_src and og_image tags. + if (!$entity->field_uw_meta_image->target_id) { + $metatags['image_src'] = 'https://uwaterloo.ca/university-of-waterloo-logo-152.png'; + $metatags['og_image'] = 'https://uwaterloo.ca/university-of-waterloo-logo-152.png'; + } } }