esmero / strawberryfield

A Field of strawberries
GNU Lesser General Public License v3.0
10 stars 5 forks source link

All you can do with Views #167

Open giancarlobi opened 3 years ago

giancarlobi commented 3 years ago

@DiegoPino, @pcambra , @alliomeria this is not a really issue while a place where we can share info and experience about using Views with Archipelago. Do you agree with this? If not I can close and delete it.

giancarlobi commented 3 years ago

A first test was create a child view to display a page of a document (pdf), i.e. when a fulltext search returns ADOs and Page as SBF Flavour Ocr. The idea is in the main View of search call by drupal_view (see twig tweak) a child view based on processor type, in this case ocr. The child require 3 variables as contextual filters: parent_id, sequence_id and processor_id. So in the main view we can extract fields processor ID, sequence ID and parent ID then hide the first and the second while parent could be rewrite with

`{{ drupal_view('sbf_flavour_ocr', 'block', parent_id, sequence_id, processor_id) }}`

In the child with a single global custom text we can manage with twig all needs to display the single page, for example a minimal basic twig template could be:

{% set iiif_server = drupal_config('format_strawberryfield.iiif_settings', 'pub_server_url') %}
{% set field = drupal_field('field_descriptive_metadata', 'node', raw_arguments.parent_id)  %}
{% set sbfjson = field.0.json['#markup'] %}
{% set data = sbfjson|json_decode(true) %}
{# <---- SETUP ---> #}
{# -- NOTE: for loops are scoped so if we onlt define source inside one it will not be accesible from the outside- #}
{% set source = '' %}
{# -- The Desired width -- #}
{% set width = 240 %}
{# -- The IIIF Server URLS -- #}
{% set Webserverurl = url('<front>')|render|replace({':8001/':''}) ~ ':8183/iiif/2/' %}
{% set IIIFserverurl = iiif_server ? iiif_server ~ '/': Webserverurl %}
{% if attribute(data, 'as:document')|length > 0 %}
{% set break = false %}
{% for document in data['as:document'] if not break %}
{% if document['flv:exif'].MIMEType == "application/pdf" and document['flv:exif'].PageCount > 0 %}
{% set cantaloupeid = IIIFserverurl ~ document['url']|replace({'s3://':''})|replace({'private://':''})|url_encode %}
{% set source = cantaloupeid ~ "/full/" ~ width ~ ",/0/default.jpg?page=" ~ arguments.sequence_id %}
{% set break = true %}
{% endif%}
{% endfor %}
{% endif%}
{% if source|length > 0 %}
<p>Page {{ arguments.sequence_id }}</p>
<img class="field-iiif image-iiif img-fluid rounded" id="thumb_iiif-field_descriptive_metadata-{{ parent.id }}-0-image1" src="{{ source }}" width="240" alt="Thumbnail for parent ADO" typeof="foaf:Image">{% endif %}

In addition to twig_tweak we need also twig_tools to be able to json_decode. Attached the main and child view, just an example, not for production.

views.view.duplicate_of_solr_search_content.yml.txt views.view.sbf_flavour_ocr.yml.txt