Skip to content

Commit

Permalink
Issue-54: Finally schemas are fixed and we have linked Thumbnails (#63)
Browse files Browse the repository at this point in the history
* Fix StrawberryMetadataTwigFormatter

Settings form was using an 'item' #type wich implies a saved value in the settings. That is wrong since we needed that element only to display contextual info the user. Since i'm here also add a Link Element to the Image Formatter (around) and fix other (yes more!) wrong schema elements.

* Its '#uri 'not '#url'

* String-i-fy

* Give image_formatter a try

* That was a bad idea!

We are generating images via IIIF, we really don't want to use Drupal's entity view of files here.

* Tiny typo

* maybe nested render array works?

* Add alt?

I thought Drupal was adding this.. well no!

* No need for a type
  • Loading branch information
DiegoPino authored Feb 29, 2020
1 parent 2a70b52 commit f76822a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 21 deletions.
6 changes: 4 additions & 2 deletions config/schema/format_strawberryfield.schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,15 @@ field.formatter.settings.strawberry_image_formatter:
type: string
label: 'Whether to use global IIIF settings or not.'
number_images:
type: integer
images_type:
type: string
image_type:
type: string
quality:
type: string
rotation:
type: string
image_link:
type: boolean
field.formatter.settings.strawberry_media_formatter:
type: mapping
label: 'Specific Config for strawberry_media_formatter'
Expand Down
46 changes: 29 additions & 17 deletions src/Plugin/Field/FieldFormatter/StrawberryImageFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*
* @FieldFormatter(
* id = "strawberry_image_formatter",
* label = @Translation("Strawberry Field Image Formatter for IIIF media"),
* label = @Translation("Strawberry Field Simple Image Formatter using IIIF"),
* class = "\Drupal\format_strawberryfield\Plugin\Field\FieldFormatter\StrawberryImageFormatter",
* field_types = {
* "strawberryfield_field"
Expand All @@ -45,6 +45,7 @@ public static function defaultSettings() {
'number_images' => 1,
'quality' => 'default',
'rotation' => '0',
'image_link' => TRUE,
];
}

Expand All @@ -67,6 +68,11 @@ public function settingsForm(array $form, FormStateInterface $form_state) {
'#maxlength' => 2,
'#min' => 0,
],
'image_link' => [
'#type' => 'checkbox',
'#title' => t('Link this image to the Full Node'),
'#default_value' => $this->getSetting('image_link'),
],
'max_width' => [
'#type' => 'number',
'#title' => $this->t('Maximum width'),
Expand Down Expand Up @@ -113,6 +119,9 @@ public function settingsSummary() {
'%max_height' => $this->getSetting('max_height') . ' pixels',
]
);
$summary[] = $this->t('Link to Node? %value', [
'%value' => boolval($this->getSetting('image_link')) === TRUE ? "Yes." : "No",
]);

return $summary;
}
Expand Down Expand Up @@ -238,7 +247,7 @@ public function viewElements(FieldItemListInterface $items, $langcode) {
}

$iiifserverthumb = "{$this->getIiifUrls()['public']}/{$iiifidentifier}"."/full/{$max_width},/0/default.jpg";
$elements[$delta]['media_thumb' . $i] = [
$image_render_array = [
'#theme' => 'image',
'#attributes' => [
'class' => ['field-iiif', 'image-iiif'],
Expand All @@ -253,40 +262,43 @@ public function viewElements(FieldItemListInterface $items, $langcode) {
'#width' => $max_width,
'#height' => $max_height,
];

// With Link
if (boolval($this->getSetting('image_link')) === TRUE && !$items->getEntity()->isNew()) {
$elements[$delta]['media_thumb' . $i] = [
'#type' => 'link',
'#title' => $image_render_array,
'#url' => $items->getEntity()->toUrl(),
'#attributes' => [
'alt' => $items->getEntity()->label()
]
];
}
else {
$elements[$delta]['media_thumb' . $i] = $image_render_array;
}

if (isset($item->_attributes)) {
$elements[$delta] += ['#attributes' => []];
$elements[$delta]['#attributes'] += $item->_attributes;
// Unset field item attributes since they have been included in the
// formatter output and should not be rendered in the field template.
unset($item->_attributes);
}
// @TODO deal with a lot of Media single strawberryfield
// Idea would be to allow a setting that says, A) all same viewer(aggregate)
// B) individual viewers for each?
// C) only first one?
// We will assign a group based on the UUID of the node containing this
// to idenfity all the divs that we will create. And only first one will be the container in case of many?
// so a jquery selector that uses that group as filter for a search.
// Drupal JS settings get accumulated. So in a single search results site we will have for each
// Formatter one passed. Reason we use 'innode' array using our $uniqueid
// @TODO probably better to use uuid() or the node id() instead of $uniqueid
$elements[$delta]['media'.$i]['#attributes']['data-iiif-infojson'] = $iiifpublicinfojson;
$elements[$delta]['media'.$i]['#attached']['drupalSettings']['format_strawberryfield']['openseadragon']['innode'][$uniqueid] = $nodeuuid;
}

}
else {
// @TODO Deal with no access here
// Should we put a thumb? Just hide?
// @TODO we can bring a plugin here and there that deals with
$elements[$delta]['media'.$i] = [
$elements[$delta]['media_thumb'.$i] = [
'#markup' => '<i class="fas fa-times-circle"></i>',
'#prefix' => '<span>',
'#suffix' => '</span>',
];
}
} elseif (isset($mediaitem['url'])) {
$elements[$delta]['media'.$i] = [
$elements[$delta]['media_thumb'.$i] = [
'#markup' => 'Non managed '.$mediaitem['url'],
'#prefix' => '<pre>',
'#suffix' => '</pre>',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ public function settingsForm(array $form, FormStateInterface $form_state) {

return [
'customtext' => [
'#type' => 'item',
'#markup' => '<h3>Use this form to select the template for your metadata.</h3><p>Several templates such as MODS 3.6 and a simple Object Description ship with Archipelago. To design your own template for any metadata standard you like, or see the full list of existing templates, visit <a href="/metadatadisplay/list">/metadatadisplay/list</a>. </p>',
],
'metadatadisplayentity_id' => [
Expand Down Expand Up @@ -243,7 +242,8 @@ public function viewElements(FieldItemListInterface $items, $langcode) {
continue;
}

$jsondata = json_decode($item->value, true);
$jsondata = json_decode($item->value, TRUE);

// Probably good idea to strip our own keys here
// @TODO remove private access to keys

Expand Down

0 comments on commit f76822a

Please sign in to comment.