Browse Source

Add templates for license_attribution view mode.

8.x-1.x
Alexander O'Neill 4 years ago
parent
commit
42a9884960
  1. 26
      media_attribution.module
  2. 1
      templates/field--paragraph--field-attribution-author--license-attribution.html.twig
  3. 1
      templates/field--paragraph--field-attribution-source--license-attribution.html.twig
  4. 2
      templates/paragraph--license-attribution--license-attribution.html.twig

26
media_attribution.module

@ -78,6 +78,19 @@ function media_attribution_modules_installed($modules) {
media_attribution_load_default_licenses(); 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(). * 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',
],
];
}

1
templates/field--paragraph--field-attribution-author--license-attribution.html.twig

@ -0,0 +1 @@
{{ source_prefix }} {{ items.0 }}

1
templates/field--paragraph--field-attribution-source--license-attribution.html.twig

@ -0,0 +1 @@
{{ items.0 }}

2
templates/paragraph--license-attribution--license-attribution.html.twig

@ -0,0 +1,2 @@
&ldquo;<cite>{{ elements.field_attribution_source.0 }}</cite>&rdquo; {{ elements.field_attribution_author }}.
<span class="license-prefix"> {{ license_prefix }} {{ license_link }}</span>
Loading…
Cancel
Save