From 03ffb863671e720950597e3fc39dfad1aad17703 Mon Sep 17 00:00:00 2001 From: Camilo Villamizar Date: Thu, 30 Nov 2023 14:48:34 -0400 Subject: [PATCH] EMMR-111 Fix null reference errors on marginalia update --- custom/modules/emmr_core/emmr_core.module | 24 +++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/custom/modules/emmr_core/emmr_core.module b/custom/modules/emmr_core/emmr_core.module index b40b19b..b1826a9 100644 --- a/custom/modules/emmr_core/emmr_core.module +++ b/custom/modules/emmr_core/emmr_core.module @@ -237,18 +237,18 @@ function emmr_core_node_presave($node) { // Iterate. foreach ($matches as $key => $marginalia) { // Get full expression match - $original = $marginalia[0]; - // Get number segment. - preg_match_all('/(.*?)<\/span>/', $original, $number); - // Build sequential number segment. - $i = $key + 1; - $new = "$i"; - // Replace original number segment in original match. - $replacement = str_replace($number[0], $new, $original, $count); - // Replace marginalia segment in transcription. - $trans = str_replace($marginalia, $replacement, $trans, $count); - // Update field and save. - if ($trans != $node->field_recipe_transcription->getValue()[0]['value']) { + $original = $marginalia[0] ?? NULL; + if ($original) { + // Get number segment. + preg_match_all('/(.*?)<\/span>/', $original, $number); + // Build sequential number segment. + $i = $key + 1; + $new = "$i"; + // Replace original number segment in original match. + $replacement = str_replace($number[0], $new, $original, $count); + // Replace marginalia segment in transcription. + $trans = str_replace($marginalia, $replacement, $trans, $count); + // Update field and save. $node->field_recipe_transcription->setValue([ 'value' => $trans, 'format' => 'unb_libraries',