Skip to content

Commit

Permalink
EMMR-111 Fix null reference errors on marginalia update
Browse files Browse the repository at this point in the history
  • Loading branch information
camilocodes committed Nov 30, 2023
1 parent efaf4a4 commit 03ffb86
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions custom/modules/emmr_core/emmr_core.module
Original file line number Diff line number Diff line change
Expand Up @@ -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 class="trxn-number">(.*?)<\/span>/', $original, $number);
// Build sequential number segment.
$i = $key + 1;
$new = "<span class='trxn-number'>$i</span>";
// 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 class="trxn-number">(.*?)<\/span>/', $original, $number);
// Build sequential number segment.
$i = $key + 1;
$new = "<span class='trxn-number'>$i</span>";
// 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',
Expand Down

0 comments on commit 03ffb86

Please sign in to comment.