|
|
|
@ -59,6 +59,7 @@ function media_attribution_modules_installed($modules) {
|
|
|
|
|
'collapse_edit_all' => 'collapse_edit_all', |
|
|
|
|
] |
|
|
|
|
], |
|
|
|
|
'weight' => 35, |
|
|
|
|
'type' => 'paragraphs', |
|
|
|
|
]) |
|
|
|
|
->save(); |
|
|
|
@ -70,7 +71,7 @@ function media_attribution_modules_installed($modules) {
|
|
|
|
|
$view_entity->setComponent('field_image_attribution', [ |
|
|
|
|
'type' => 'entity_reference_revisions_entity_view', |
|
|
|
|
'label' => 'hidden', |
|
|
|
|
'settings' => ['view_mode' => 'default', 'link' => ''], |
|
|
|
|
'settings' => ['view_mode' => 'license_attribution', 'link' => ''], |
|
|
|
|
])->save(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -78,6 +79,21 @@ 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'); |
|
|
|
|
$items = isset($variables['elements']['field_license']['#items']) ? $variables['elements']['field_license']['#items'] : []; |
|
|
|
|
if (!empty($items)) { |
|
|
|
|
$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(). |
|
|
|
|
* |
|
|
|
@ -89,12 +105,13 @@ function media_attribution_preprocess_entity_embed_container(&$variables) {
|
|
|
|
|
&& $attributions = $variables['element']['#entity']->get('field_image_attribution') |
|
|
|
|
->referencedEntities()) { |
|
|
|
|
$attribution = $attributions[0]; |
|
|
|
|
$author = $attribution->get('field_attribution_author')->getValue()[0]; |
|
|
|
|
$author_field = $attribution->get('field_attribution_author')->getValue(); |
|
|
|
|
$author = isset($author_field[0]) ? $author_field[0] : ''; |
|
|
|
|
|
|
|
|
|
$source = $attribution->get('field_attribution_source')->getValue()[0]; |
|
|
|
|
$source = $attribution->get('field_attribution_source')->count() > 0 ? $attribution->get('field_attribution_source')->getValue()[0] : ''; |
|
|
|
|
$license = $attribution->get('field_license')->entity; |
|
|
|
|
$license_link = !empty($license) ? $license->get('field_license_link')->getValue()[0] : FALSE; |
|
|
|
|
$attribution_note = $attribution->get('field_attribution_note')->getValue()[0]; |
|
|
|
|
$attribution_note = $attribution->get('field_attribution_note')->count() > 0 ? $attribution->get('field_attribution_note')->getValue()[0]: ''; |
|
|
|
|
$attribution_text = []; |
|
|
|
|
if (!empty($source['uri'])) { |
|
|
|
|
$attribution_text['source'] = [ |
|
|
|
@ -132,10 +149,11 @@ function media_attribution_preprocess_entity_embed_container(&$variables) {
|
|
|
|
|
'#prefix' => ' ', |
|
|
|
|
]; |
|
|
|
|
} |
|
|
|
|
$children = ['#markup' => $variables['children']]; |
|
|
|
|
$variables['children'] = [ |
|
|
|
|
'first' => [ |
|
|
|
|
'#type' => 'markup', |
|
|
|
|
'#markup' => render($variables['children']) |
|
|
|
|
'#markup' => \Drupal::service('renderer')->render($children) |
|
|
|
|
], |
|
|
|
|
$attribution_text |
|
|
|
|
]; |
|
|
|
@ -145,13 +163,26 @@ function media_attribution_preprocess_entity_embed_container(&$variables) {
|
|
|
|
|
* Read the list of pre-defined Creative Commons media_attribution_licenses and create corresponding taxonomy terms. |
|
|
|
|
*/ |
|
|
|
|
function media_attribution_load_default_licenses() { |
|
|
|
|
$file_path = drupal_get_path('module', 'media_attribution') . '/media_attribution.default.licenses.yml'; |
|
|
|
|
$file_path = \Drupal::service('extension.list.module')->getPath('media_attribution') . '/media_attribution.default.licenses.yml'; |
|
|
|
|
$file_contents = file_get_contents($file_path); |
|
|
|
|
$license_data = Yaml::decode($file_contents); |
|
|
|
|
|
|
|
|
|
foreach ($license_data as $license_item) { |
|
|
|
|
$icon_file_path = drupal_get_path('module', 'media_attribution') . "/" . $license_item['icon_file']; |
|
|
|
|
$icon_file_path = \Drupal::service('extension.list.module')->getPath('media_attribution') . "/" . $license_item['icon_file']; |
|
|
|
|
LicenseLoader::createLicenseTerm($license_item['title'],$license_item['short_label'], $icon_file_path, $license_item['url']); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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', |
|
|
|
|
], |
|
|
|
|
]; |
|
|
|
|
} |
|
|
|
|