Browse Source

Initial commit.

wip
Alexander O'Neill 6 years ago
commit
cd40aed829
  1. 14
      composer.json
  2. 60
      config/optional/core.entity_form_display.media.image.default.yml
  3. 65
      config/optional/core.entity_form_display.media.image.media_browser.yml
  4. 44
      config/optional/core.entity_form_display.paragraph.license_attribution.default.yml
  5. 46
      config/optional/core.entity_form_display.taxonomy_term.licenses.default.yml
  6. 42
      config/optional/core.entity_view_display.media.image.default.yml
  7. 52
      config/optional/core.entity_view_display.media.image.embedded.yml
  8. 48
      config/optional/core.entity_view_display.paragraph.license_attribution.default.yml
  9. 13
      config/optional/core.entity_view_mode.paragraph.license_attribution.yml
  10. 37
      config/optional/field.field.media.image.field_image_attribution.yml
  11. 26
      config/optional/field.field.paragraph.license_attribution.field_attribution_author.yml
  12. 26
      config/optional/field.field.paragraph.license_attribution.field_attribution_source.yml
  13. 33
      config/optional/field.field.paragraph.license_attribution.field_license.yml
  14. 26
      config/optional/field.field.taxonomy_term.licenses.field_license_link.yml
  15. 24
      config/optional/field.storage.media.field_image_attribution.yml
  16. 22
      config/optional/field.storage.paragraph.field_attribution_author.yml
  17. 22
      config/optional/field.storage.paragraph.field_attribution_source.yml
  18. 23
      config/optional/field.storage.paragraph.field_license.yml
  19. 22
      config/optional/field.storage.taxonomy_term.field_license_link.yml
  20. 8
      config/optional/paragraphs.paragraphs_type.license_attribution.yml
  21. 8
      config/optional/taxonomy.vocabulary.licenses.yml
  22. 8
      entity_embed_attribution.info.yml
  23. 124
      entity_embed_attribution.module

14
composer.json

@ -0,0 +1,14 @@
{
"name": "drupal/entity_embed_attribution",
"type": "drupal-module",
"description": "Attach an attribution and license info to embedded media",
"keywords": ["Drupal"],
"license": "GPL-2.0+",
"homepage": "https://www.drupal.org/project/entity_embed_attribution",
"minimum-stability": "dev",
"support": {
"issues": "https://www.drupal.org/project/issues/entity_embed_attribution",
"source": "http://cgit.drupalcode.org/entity_embed_attribution"
},
"require": { }
}

60
config/optional/core.entity_form_display.media.image.default.yml

@ -0,0 +1,60 @@
langcode: en
status: true
dependencies:
config:
- field.field.media.image.field_image_attribution
- field.field.media.image.field_media_in_library
- field.field.media.image.image
- image.style.thumbnail
- media.type.image
module:
- image
- paragraphs
_core:
default_config_hash: kyoAHlZTGIuGTaQuBblGBk8EhfnVKOl19_0j5WbpQqM
id: media.image.default
targetEntityType: media
bundle: image
mode: default
content:
field_image_attribution:
type: entity_reference_paragraphs
weight: 3
settings:
title: Paragraph
title_plural: Paragraphs
edit_mode: open
add_mode: dropdown
form_display_mode: default
default_paragraph_type: ''
third_party_settings: { }
region: content
field_media_in_library:
type: boolean_checkbox
weight: 2
settings:
display_label: true
third_party_settings: { }
region: content
image:
type: image_image
weight: 0
settings:
progress_indicator: throbber
preview_image_style: thumbnail
third_party_settings: { }
region: content
name:
type: string_textfield
weight: 1
settings:
size: 60
placeholder: ''
third_party_settings: { }
region: content
hidden:
created: true
moderation_state: true
path: true
status: true
uid: true

65
config/optional/core.entity_form_display.media.image.media_browser.yml

@ -0,0 +1,65 @@
langcode: en
status: true
dependencies:
config:
- core.entity_form_mode.media.media_browser
- field.field.media.image.field_image_attribution
- field.field.media.image.field_media_in_library
- field.field.media.image.image
- image.style.medium
- media.type.image
module:
- image
- lightning_media
- paragraphs
_core:
default_config_hash: iVmRBD7y3Gmddt29sSx9DwwH6Q4UaROqMu7FLyy_bvQ
id: media.image.media_browser
targetEntityType: media
bundle: image
mode: media_browser
content:
field_image_attribution:
type: entity_reference_paragraphs
weight: 3
region: content
settings:
title: Paragraph
title_plural: Paragraphs
edit_mode: open
add_mode: dropdown
form_display_mode: default
default_paragraph_type: ''
third_party_settings: { }
field_media_in_library:
type: boolean_checkbox
weight: 2
settings:
display_label: true
third_party_settings: { }
region: content
image:
type: image_image
weight: 0
settings:
preview_image_style: medium
progress_indicator: throbber
third_party_settings:
lightning_media:
file_links: false
remove_button: false
region: content
name:
type: string_textfield
weight: 1
settings:
size: 60
placeholder: ''
third_party_settings: { }
region: content
hidden:
created: true
moderation_state: true
path: true
status: true
uid: true

44
config/optional/core.entity_form_display.paragraph.license_attribution.default.yml

@ -0,0 +1,44 @@
langcode: en
status: true
dependencies:
config:
- field.field.paragraph.license_attribution.field_attribution_author
- field.field.paragraph.license_attribution.field_attribution_source
- field.field.paragraph.license_attribution.field_license
- paragraphs.paragraphs_type.license_attribution
module:
- link
id: paragraph.license_attribution.default
targetEntityType: paragraph
bundle: license_attribution
mode: default
content:
field_attribution_author:
weight: 1
settings:
placeholder_url: ''
placeholder_title: ''
third_party_settings: { }
type: link_default
region: content
field_attribution_source:
weight: 0
settings:
placeholder_url: ''
placeholder_title: ''
third_party_settings: { }
type: link_default
region: content
field_license:
weight: 2
settings:
match_operator: CONTAINS
size: 60
placeholder: ''
third_party_settings: { }
type: entity_reference_autocomplete
region: content
hidden:
created: true
status: true
uid: true

46
config/optional/core.entity_form_display.taxonomy_term.licenses.default.yml

@ -0,0 +1,46 @@
langcode: en
status: true
dependencies:
config:
- field.field.taxonomy_term.licenses.field_license_link
- taxonomy.vocabulary.licenses
module:
- link
- path
- text
id: taxonomy_term.licenses.default
targetEntityType: taxonomy_term
bundle: licenses
mode: default
content:
description:
type: text_textfield
weight: 0
region: content
settings:
size: 60
placeholder: ''
third_party_settings: { }
field_license_link:
weight: 31
settings:
placeholder_url: ''
placeholder_title: ''
third_party_settings: { }
type: link_default
region: content
name:
type: string_textfield
weight: -5
region: content
settings:
size: 60
placeholder: ''
third_party_settings: { }
path:
type: path
weight: 30
region: content
settings: { }
third_party_settings: { }
hidden: { }

42
config/optional/core.entity_view_display.media.image.default.yml

@ -0,0 +1,42 @@
langcode: en
status: true
dependencies:
config:
- field.field.media.image.field_image_attribution
- field.field.media.image.field_media_in_library
- field.field.media.image.image
- media.type.image
module:
- entity_reference_revisions
- image
_core:
default_config_hash: VLDxfMVPTkd2xvOjFMCh3kWmaOYnd03zggFXuUXQVEY
id: media.image.default
targetEntityType: media
bundle: image
mode: default
content:
field_image_attribution:
type: entity_reference_revisions_entity_view
weight: 1
label: hidden
settings:
view_mode: default
link: ''
third_party_settings: { }
region: content
image:
type: image
weight: 0
label: hidden
settings:
image_style: ''
image_link: ''
third_party_settings: { }
region: content
hidden:
created: true
field_media_in_library: true
name: true
thumbnail: true
uid: true

52
config/optional/core.entity_view_display.media.image.embedded.yml

@ -0,0 +1,52 @@
langcode: en
status: true
dependencies:
config:
- core.entity_view_mode.media.embedded
- field.field.media.image.field_image_attribution
- field.field.media.image.field_media_in_library
- field.field.media.image.image
- media.type.image
module:
- entity_reference_revisions
- image
_core:
default_config_hash: FaHkkj9J9DxKQ-R7RNddSDq_d0D6UBY3hoKzoAQoGaw
id: media.image.embedded
targetEntityType: media
bundle: image
mode: embedded
content:
created:
type: timestamp
weight: 2
region: content
label: above
settings:
date_format: medium
custom_date_format: ''
timezone: ''
third_party_settings: { }
field_image_attribution:
type: entity_reference_revisions_entity_view
weight: 1
region: content
label: hidden
settings:
view_mode: default
link: ''
third_party_settings: { }
image:
type: image
weight: 0
label: hidden
settings:
image_style: ''
image_link: ''
third_party_settings: { }
region: content
hidden:
field_media_in_library: true
name: true
thumbnail: true
uid: true

48
config/optional/core.entity_view_display.paragraph.license_attribution.default.yml

@ -0,0 +1,48 @@
langcode: en
status: true
dependencies:
config:
- field.field.paragraph.license_attribution.field_attribution_author
- field.field.paragraph.license_attribution.field_attribution_source
- field.field.paragraph.license_attribution.field_license
- paragraphs.paragraphs_type.license_attribution
module:
- link
id: paragraph.license_attribution.default
targetEntityType: paragraph
bundle: license_attribution
mode: default
content:
field_attribution_author:
weight: 1
label: above
settings:
trim_length: 80
url_only: false
url_plain: false
rel: ''
target: ''
third_party_settings: { }
type: link
region: content
field_attribution_source:
weight: 0
label: above
settings:
trim_length: 80
url_only: false
url_plain: false
rel: ''
target: ''
third_party_settings: { }
type: link
region: content
field_license:
weight: 2
label: above
settings:
link: true
third_party_settings: { }
type: entity_reference_label
region: content
hidden: { }

13
config/optional/core.entity_view_mode.paragraph.license_attribution.yml

@ -0,0 +1,13 @@
langcode: en
status: true
dependencies:
module:
- lightning_core
- paragraphs
third_party_settings:
lightning_core:
description: ''
id: paragraph.license_attribution
label: 'License attribution'
targetEntityType: paragraph
cache: true

37
config/optional/field.field.media.image.field_image_attribution.yml

@ -0,0 +1,37 @@
langcode: en
status: true
dependencies:
config:
- field.storage.media.field_image_attribution
- media.type.image
- paragraphs.paragraphs_type.license_attribution
module:
- entity_reference_revisions
- require_on_publish
third_party_settings:
require_on_publish:
require_on_publish: false
id: media.image.field_image_attribution
field_name: field_image_attribution
entity_type: media
bundle: image
label: 'Image Attribution'
description: ''
required: false
translatable: false
default_value: { }
default_value_callback: ''
settings:
handler: 'default:paragraph'
handler_settings:
negate: 0
target_bundles:
license_attribution: license_attribution
target_bundles_drag_drop:
author_with_affiliation:
weight: 3
enabled: false
license_attribution:
enabled: true
weight: 4
field_type: entity_reference_revisions

26
config/optional/field.field.paragraph.license_attribution.field_attribution_author.yml

@ -0,0 +1,26 @@
langcode: en
status: true
dependencies:
config:
- field.storage.paragraph.field_attribution_author
- paragraphs.paragraphs_type.license_attribution
module:
- link
- require_on_publish
third_party_settings:
require_on_publish:
require_on_publish: false
id: paragraph.license_attribution.field_attribution_author
field_name: field_attribution_author
entity_type: paragraph
bundle: license_attribution
label: Author
description: 'Link to the author''s home page.'
required: false
translatable: false
default_value: { }
default_value_callback: ''
settings:
link_type: 17
title: 2
field_type: link

26
config/optional/field.field.paragraph.license_attribution.field_attribution_source.yml

@ -0,0 +1,26 @@
langcode: en
status: true
dependencies:
config:
- field.storage.paragraph.field_attribution_source
- paragraphs.paragraphs_type.license_attribution
module:
- link
- require_on_publish
third_party_settings:
require_on_publish:
require_on_publish: false
id: paragraph.license_attribution.field_attribution_source
field_name: field_attribution_source
entity_type: paragraph
bundle: license_attribution
label: Source
description: 'Link to the work''s original source. Set the link text as the title of the work.'
required: false
translatable: false
default_value: { }
default_value_callback: ''
settings:
link_type: 17
title: 2
field_type: link

33
config/optional/field.field.paragraph.license_attribution.field_license.yml

@ -0,0 +1,33 @@
langcode: en
status: true
dependencies:
config:
- field.storage.paragraph.field_license
- paragraphs.paragraphs_type.license_attribution
- taxonomy.vocabulary.licenses
module:
- require_on_publish
third_party_settings:
require_on_publish:
require_on_publish: false
id: paragraph.license_attribution.field_license
field_name: field_license
entity_type: paragraph
bundle: license_attribution
label: License
description: ''
required: true
translatable: false
default_value: { }
default_value_callback: ''
settings:
handler: 'default:taxonomy_term'
handler_settings:
target_bundles:
licenses: licenses
sort:
field: name
direction: asc
auto_create: false
auto_create_bundle: ''
field_type: entity_reference

26
config/optional/field.field.taxonomy_term.licenses.field_license_link.yml

@ -0,0 +1,26 @@
langcode: en
status: true
dependencies:
config:
- field.storage.taxonomy_term.field_license_link
- taxonomy.vocabulary.licenses
module:
- link
- require_on_publish
third_party_settings:
require_on_publish:
require_on_publish: false
id: taxonomy_term.licenses.field_license_link
field_name: field_license_link
entity_type: taxonomy_term
bundle: licenses
label: 'License link'
description: ''
required: true
translatable: false
default_value: { }
default_value_callback: ''
settings:
link_type: 17
title: 2
field_type: link

24
config/optional/field.storage.media.field_image_attribution.yml

@ -0,0 +1,24 @@
langcode: en
status: true
dependencies:
module:
- entity_reference_revisions
- field_permissions
- media
- paragraphs
third_party_settings:
field_permissions:
permission_type: public
id: media.field_image_attribution
field_name: field_image_attribution
entity_type: media
type: entity_reference_revisions
settings:
target_type: paragraph
module: entity_reference_revisions
locked: false
cardinality: 1
translatable: true
indexes: { }
persist_with_no_fields: false
custom_storage: false

22
config/optional/field.storage.paragraph.field_attribution_author.yml

@ -0,0 +1,22 @@
langcode: en
status: true
dependencies:
module:
- field_permissions
- link
- paragraphs
third_party_settings:
field_permissions:
permission_type: public
id: paragraph.field_attribution_author
field_name: field_attribution_author
entity_type: paragraph
type: link
settings: { }
module: link
locked: false
cardinality: 1
translatable: true
indexes: { }
persist_with_no_fields: false
custom_storage: false

22
config/optional/field.storage.paragraph.field_attribution_source.yml

@ -0,0 +1,22 @@
langcode: en
status: true
dependencies:
module:
- field_permissions
- link
- paragraphs
third_party_settings:
field_permissions:
permission_type: public
id: paragraph.field_attribution_source
field_name: field_attribution_source
entity_type: paragraph
type: link
settings: { }
module: link
locked: false
cardinality: 1
translatable: true
indexes: { }
persist_with_no_fields: false
custom_storage: false

23
config/optional/field.storage.paragraph.field_license.yml

@ -0,0 +1,23 @@
langcode: en
status: true
dependencies:
module:
- field_permissions
- paragraphs
- taxonomy
third_party_settings:
field_permissions:
permission_type: public
id: paragraph.field_license
field_name: field_license
entity_type: paragraph
type: entity_reference
settings:
target_type: taxonomy_term
module: core
locked: false
cardinality: 1
translatable: true
indexes: { }
persist_with_no_fields: false
custom_storage: false

22
config/optional/field.storage.taxonomy_term.field_license_link.yml

@ -0,0 +1,22 @@
langcode: en
status: true
dependencies:
module:
- field_permissions
- link
- taxonomy
third_party_settings:
field_permissions:
permission_type: public
id: taxonomy_term.field_license_link
field_name: field_license_link
entity_type: taxonomy_term
type: link
settings: { }
module: link
locked: false
cardinality: 1
translatable: true
indexes: { }
persist_with_no_fields: false
custom_storage: false

8
config/optional/paragraphs.paragraphs_type.license_attribution.yml

@ -0,0 +1,8 @@
langcode: en
status: true
dependencies: { }
id: license_attribution
label: 'License Attribution'
icon_uuid: null
description: 'Indicate the source and license conditions of a piece of content.'
behavior_plugins: { }

8
config/optional/taxonomy.vocabulary.licenses.yml

@ -0,0 +1,8 @@
langcode: en
status: true
dependencies: { }
name: Licenses
vid: licenses
description: 'Licenses for content and attribution.'
hierarchy: 0
weight: 0

8
entity_embed_attribution.info.yml

@ -0,0 +1,8 @@
name: 'Entity Embed Attribution'
type: module
description: 'Attach an attribution and license info to embedded media'
core: 8.x
package: 'media'
dependencies:
- media
- paragraphs

124
entity_embed_attribution.module

@ -0,0 +1,124 @@
<?php
/**
* @file
* Contains entity_embed_attribution.module.
*/
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url;
use Drupal\Core\Render\Markup;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
/**
* Implements hook_help().
*/
function entity_embed_attribution_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
// Main module help for the entity_embed_attribution module.
case 'help.page.entity_embed_attribution':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('Attach an attribution and license info to embedded media') . '</p>';
return $output;
default:
}
}
/**
* Implements hook_modules_installed().
*
* Add attribution form to media embed forms and view displays.
*/
function entity_embed_attribution_modules_installed($modules) {
foreach (['media_browser', 'default'] as $form_variant) {
$form_entity = EntityFormDisplay::load("media.image.$form_variant");
$form_entity->setComponent('field_image_attribution',
[
'region' => 'content',
'settings' => [
'title' => 'Paragraph',
'title_plural' => 'Paragraphs',
'edit_mode' => 'open',
'closed_mode' => 'summary',
'autocollapse' => 'none',
'closed_mode_threshold' => 0,
'add_mode' => 'dropdown',
'form_display_mode' => 'default',
'default_paragraph_type' => '',
'features' => [
'duplicate' => 'duplicate',
'collapse_edit_all' => 'collapse_edit_all',
]
],
'type' => 'paragraphs',
])
->save();
}
foreach (['embedded', 'default'] as $entity_view_variant) {
$view_entity = EntityViewDisplay::load("media.image.$entity_view_variant");
$view_entity->setComponent('field_image_attribution', [
'type' => 'entity_reference_revisions_entity_view',
'label' => 'hidden',
'settings' => ['view_mode' => 'default', 'link' => ''],
])->save();
}
}
/**
* Implementation of hook_preprocess_entity_embed_container().
*
* @param $variables
*/
function entity_embed_attribution_preprocess_entity_embed_container(&$variables) {
if ($attributions = $variables['element']['#entity']->get('field_image_attribution')->referencedEntities()) {
$attribution = $attributions[0];
$author = $attribution->get('field_attribution_author')->getValue()[0];
$source = $attribution->get('field_attribution_source')->getValue()[0];
$license = $attribution->get('field_license')->entity;
$license_link = $license->get('field_license_link')->getValue()[0];
$attribution_text = [
'source' => [
'#type' => 'link',
'#title' => $source['title'],
'#prefix' => "<br>&ldquo;<cite>",
'#suffix' => "</cite>&rdquo;",
'#url' => Url::fromUri($source['uri']),
],
];
}
if (!empty($author)) {
$attribution_text['author'] = [
'#type' => 'link',
'#title' => $author['title'],
'#prefix' => ' ' . t('by') . ' ',
'#url' => Url::fromUri($author['uri']),
];
}
if (!empty($license_link)) {
$attribution_text['license'] = [
'#type' => 'link',
'#title' => $license_link['title'],
'#prefix' => ' ' . t('is licensec under') . ' ',
'#url' => Url::fromUri($license_link['uri']),
'#suffix' => '.',
];
}
// $attribution_string = \Drupal::render($attribution_text);
$variables['children'] = ['first' => ['#type' => 'markup', '#markup' => render($variables['children'])],
$attribution_text
];
}
Loading…
Cancel
Save