Skip to content

Commit

Permalink
EMMR-111 Implement marginalia numbering, display, and claean up
Browse files Browse the repository at this point in the history
  • Loading branch information
camilocodes committed Nov 29, 2023
1 parent b9e2f87 commit efaf4a4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
29 changes: 28 additions & 1 deletion custom/modules/emmr_core/emmr_core.module
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,9 @@ function emmr_core_preprocess_node(&$variables) {
* Implements hook_ENTITY_TYPE_presave().
*/
function emmr_core_node_presave($node) {
// Clear imprecise date fields if date not imprecise.

if ($node->bundle() == "emmr_recipe") {
// Clear imprecise date fields if date not imprecise.

if (empty($node->get('field_imprecise_date')->getValue()[0]['value'])) {
$node->get('field_recipe_date_text')->setValue("");
Expand Down Expand Up @@ -228,6 +229,32 @@ function emmr_core_node_presave($node) {
}

$node->get('field_symptoms_index')->setValue($symptoms);

// Re-number transcription marginalia.
$trans = $node->field_recipe_transcription->getValue()[0]['value'];
// Find marginalia item matches.
preg_match_all('/<trxnmar>(.*?)<\/trxnmar>/', $trans, $matches);
// 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']) {
$node->field_recipe_transcription->setValue([
'value' => $trans,
'format' => 'unb_libraries',
]);
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ jQuery(document).ready(function() {
if (jQuery("#recipe-details-header").length != 0) {
// Recipe node view functionality
// Copy annotations from CKEditor to annotations panel
origin = ".field--name-field-recipe-transcription .trxn-margin";
origin = ".field--name-field-recipe-transcription trxnmar";
destin = "#recipe-anno";

// If marginalia found
Expand Down
10 changes: 6 additions & 4 deletions custom/themes/emmr_lib_unb_ca/src/scss/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,8 @@ h1.page-header > a {

/* Transcription */
trxnin, trxnin + p, p:has(+ trxnin),
trxnrep, trxnrep + p, p:has(+ trxnrep) {
trxnrep, trxnrep + p, p:has(+ trxnrep),
trxnmar, trxnmar + p, p:has(+ trxnmar) {
display: inline;
}

Expand All @@ -672,7 +673,7 @@ trxnrep, trxnrep + p, p:has(+ trxnrep) {
color: $color-red;
}

#recipe-trans .trxn-replace {
#recipe-trans .trxn-replaced {
position: relative;
bottom: -.9em;
color: $color-red;
Expand All @@ -683,7 +684,8 @@ trxnrep, trxnrep + p, p:has(+ trxnrep) {
display: inline;
width: max-content;
width: -moz-max-content;
bottom: 1.5em;
line-height: 0;
color: $color-red;
}

#recipe-trans span.emmr-anno {
Expand All @@ -695,7 +697,7 @@ trxnrep, trxnrep + p, p:has(+ trxnrep) {
bottom: 1.1em;
}

#recipe-trans .trxn-margin > .trxn-text {
#recipe-trans trxnmar > .trxn-text {
visibility: hidden !important;
}

Expand Down

0 comments on commit efaf4a4

Please sign in to comment.