From 42a9884960b5b07050e071ea339eb568f56661cf Mon Sep 17 00:00:00 2001 From: Alexander O'Neill Date: Mon, 28 Sep 2020 16:07:55 -0300 Subject: [PATCH] Add templates for license_attribution view mode. --- media_attribution.module | 26 +++++++++++++++++++ ...tion-author--license-attribution.html.twig | 1 + ...tion-source--license-attribution.html.twig | 1 + ...attribution--license-attribution.html.twig | 2 ++ 4 files changed, 30 insertions(+) create mode 100644 templates/field--paragraph--field-attribution-author--license-attribution.html.twig create mode 100644 templates/field--paragraph--field-attribution-source--license-attribution.html.twig create mode 100644 templates/paragraph--license-attribution--license-attribution.html.twig diff --git a/media_attribution.module b/media_attribution.module index db6b631..6f527ba 100644 --- a/media_attribution.module +++ b/media_attribution.module @@ -78,6 +78,19 @@ function media_attribution_modules_installed($modules) { media_attribution_load_default_licenses(); } +function media_attribution_preprocess_field__paragraph__field_attribution_author__license_attribution(&$variables) { + $variables['source_prefix'] = \Drupal::translation()->translate('by'); +} + +function media_attribution_preprocess_paragraph__license_attribution__license_attribution(&$variables) { + $variables['license_prefix'] = \Drupal::translation()->translate('Licensed under'); + + $referencedEntity = $variables['elements']['field_license']['#items'] + ->first()->get('entity')->getTarget()->getValue(); + + $variables['license_link'] = $referencedEntity->get('field_license_link')->first()->view(); +} + /** * Implementation of hook_preprocess_entity_embed_container(). * @@ -155,3 +168,16 @@ function media_attribution_load_default_licenses() { } } +function media_attribution_theme() { + return [ + 'paragraph__license_attribution__license_attribution' => [ + 'base hook' => 'paragraph', + ], + 'field__paragraph__field_attribution_source__license_attribution' => [ + 'base hook' => 'field', + ], + 'field__paragraph__field_attribution_author__license_attribution' => [ + 'base hook' => 'field', + ], + ]; +} \ No newline at end of file diff --git a/templates/field--paragraph--field-attribution-author--license-attribution.html.twig b/templates/field--paragraph--field-attribution-author--license-attribution.html.twig new file mode 100644 index 0000000..2ccb755 --- /dev/null +++ b/templates/field--paragraph--field-attribution-author--license-attribution.html.twig @@ -0,0 +1 @@ +{{ source_prefix }} {{ items.0 }} \ No newline at end of file diff --git a/templates/field--paragraph--field-attribution-source--license-attribution.html.twig b/templates/field--paragraph--field-attribution-source--license-attribution.html.twig new file mode 100644 index 0000000..5d15023 --- /dev/null +++ b/templates/field--paragraph--field-attribution-source--license-attribution.html.twig @@ -0,0 +1 @@ +{{ items.0 }} \ No newline at end of file diff --git a/templates/paragraph--license-attribution--license-attribution.html.twig b/templates/paragraph--license-attribution--license-attribution.html.twig new file mode 100644 index 0000000..1c46f23 --- /dev/null +++ b/templates/paragraph--license-attribution--license-attribution.html.twig @@ -0,0 +1,2 @@ +“{{ elements.field_attribution_source.0 }}” {{ elements.field_attribution_author }}. + {{ license_prefix }} {{ license_link }} \ No newline at end of file