Inline Data Type Combination (XML + Literal)

Hello all!

This is kind’ve a revisit to a topic I brought up last year (and got help from @fackrellj), but slightly different, plus last time I just ended up making a table since I wasn’t able to make this work.

I have a timestamped index of chapters that I want to show alongside a piece of media–either audio or video, and I have some Javascript that can highlight each line as it comes to it (I made a CodePen that works before bringing it into Omeka).

In order to make it so that I can point to which property I want to do this with, I added a “Values” element group to my theme.ini:

element_groups.property_concat_xml_lit = "Values"

elements.property_concat_xml_lit.name = "property_concat_xml_lit"
elements.property_concat_xml_lit.type = "Omeka\Form\Element\ArrayTextArea"
elements.property_concat_xml_lit.options.label = "Properties to Concatenate XML + Literal Values"
elements.property_concat_xml_lit.options.info = "List properties that have value types of both 'XML' and 'Literal' that you want joined in one line: 'XML' 'Literal'. For example: '<time>00:00:07<time><span> Transcript Chapter 1</span>'."
elements.property_concat_xml_lit.options.element_group = "property_concat_xml_lit"

To go with this addition to view/common/resource-page-block-layout (after the original if, but before the echo $resource->displayValues($options);):

$xmlLitValue = $this->themeSetting('property_concat_xml_lit');

// Check to see if there have been properties listed as needing an XML value concatted with a Literal value
// Check to see if this property is in that array
if (is_array($xmlLitValue) && in_array($this, $xmlLitValue)) {
    $propertyValues = $this->$property['values'];
    if (!empty($propertyValues)) {
        
        // Initialize arrays to hold the XML and literal values
        $xmlValues = [];
        $literalValues = [];
        
        // Iterate over each property value
        foreach ($propertyValues as $value) {
            if ($value->type() === 'xml') {
                $xmlValues[] = $value->{'@value'};
            } elseif ($value->type() === 'literal') {
                $literalValues[] = $value->{'@value'};
            }
        }
        // Make sure both arrays have the same number of values
        $totalItems = min(count($xmlValues), count($literalValues));
        
        // Output the combined result
        for ($i = 0; $i < $totalItems; $i++) {
            echo $xmlValues[$i] . " " . $literalValues[$i] . "<br>";
        }
    };
};

I’m still learning how to fiddle with my theme, so I’m not exactly surprised it’s not working. What am I missing?

1 Like