Browse Source

Add default licenses and icons.

wip
Alexander O'Neill 6 years ago
parent
commit
a10dab4812
  1. 39
      config/optional/core.entity_form_display.taxonomy_term.licenses.default.yml
  2. 52
      config/optional/core.entity_view_display.taxonomy_term.licenses.default.yml
  3. 41
      config/optional/field.field.taxonomy_term.licenses.field_license_icon.yml
  4. 33
      config/optional/field.storage.taxonomy_term.field_license_icon.yml
  5. 31
      entity_embed_attribution.default.licenses.yml
  6. 53
      entity_embed_attribution.module
  7. BIN
      images/by-nc-nd.png
  8. BIN
      images/by-nc-sa.eu.png
  9. BIN
      images/by-nc-sa.png
  10. BIN
      images/by-nc.eu.png
  11. BIN
      images/by-nc.png
  12. BIN
      images/by-nd.png
  13. BIN
      images/by-sa.png
  14. BIN
      images/by.png
  15. BIN
      images/publicdomain.png

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

@ -2,27 +2,45 @@ langcode: en
status: true status: true
dependencies: dependencies:
config: config:
- entity_browser.browser.image_browser
- field.field.taxonomy_term.licenses.field_license_icon
- field.field.taxonomy_term.licenses.field_license_link - field.field.taxonomy_term.licenses.field_license_link
- taxonomy.vocabulary.licenses - taxonomy.vocabulary.licenses
module: module:
- entity_browser
- link - link
- path
- text - text
_core:
default_config_hash: GeroQ_nB3tqP5g0Z5B4UShGyIomjdHA8hDn73kSFYgc
id: taxonomy_term.licenses.default id: taxonomy_term.licenses.default
targetEntityType: taxonomy_term targetEntityType: taxonomy_term
bundle: licenses bundle: licenses
mode: default mode: default
content: content:
description: description:
type: text_textfield type: text_textarea
weight: 0 weight: 3
region: content region: content
settings: settings:
size: 60
placeholder: '' placeholder: ''
rows: 5
third_party_settings: { }
field_license_icon:
type: entity_browser_file
weight: 2
settings:
entity_browser: image_browser
field_widget_edit: true
field_widget_remove: true
view_mode: default
preview_image_style: thumbnail
open: true
field_widget_replace: false
selection_mode: selection_append
region: content
third_party_settings: { } third_party_settings: { }
field_license_link: field_license_link:
weight: 31 weight: 1
settings: settings:
placeholder_url: '' placeholder_url: ''
placeholder_title: '' placeholder_title: ''
@ -31,16 +49,11 @@ content:
region: content region: content
name: name:
type: string_textfield type: string_textfield
weight: -5 weight: 0
region: content region: content
settings: settings:
size: 60 size: 60
placeholder: '' placeholder: ''
third_party_settings: { } third_party_settings: { }
path: hidden:
type: path path: true
weight: 30
region: content
settings: { }
third_party_settings: { }
hidden: { }

52
config/optional/core.entity_view_display.taxonomy_term.licenses.default.yml

@ -0,0 +1,52 @@
langcode: en
status: true
dependencies:
config:
- field.field.taxonomy_term.licenses.field_license_icon
- field.field.taxonomy_term.licenses.field_license_link
- taxonomy.vocabulary.licenses
module:
- image
- link
- panelizer
- text
third_party_settings:
panelizer:
enable: false
custom: false
allow: false
default: default
id: taxonomy_term.licenses.default
targetEntityType: taxonomy_term
bundle: licenses
mode: default
content:
description:
label: hidden
type: text_default
weight: 1
region: content
settings: { }
third_party_settings: { }
field_license_icon:
weight: 2
label: above
settings:
image_style: ''
image_link: ''
third_party_settings: { }
type: image
region: content
field_license_link:
type: link
weight: 0
region: content
label: above
settings:
trim_length: 80
url_only: false
url_plain: false
rel: ''
target: ''
third_party_settings: { }
hidden: { }

41
config/optional/field.field.taxonomy_term.licenses.field_license_icon.yml

@ -0,0 +1,41 @@
langcode: en
status: true
dependencies:
config:
- field.storage.taxonomy_term.field_license_icon
- taxonomy.vocabulary.licenses
module:
- image
- require_on_publish
third_party_settings:
require_on_publish:
require_on_publish: false
id: taxonomy_term.licenses.field_license_icon
field_name: field_license_icon
entity_type: taxonomy_term
bundle: licenses
label: 'License Icon'
description: 'Icon used to identify license rights, standardized by <a href="https://www.creativecommons.org/">Creative Commons.</a>.'
required: false
translatable: false
default_value: { }
default_value_callback: ''
settings:
file_directory: '[date:custom:Y]-[date:custom:m]'
file_extensions: 'png gif jpg jpeg'
max_filesize: ''
max_resolution: ''
min_resolution: ''
alt_field: true
alt_field_required: true
title_field: false
title_field_required: false
default_image:
uuid: ''
alt: ''
title: ''
width: null
height: null
handler: 'default:file'
handler_settings: { }
field_type: image

33
config/optional/field.storage.taxonomy_term.field_license_icon.yml

@ -0,0 +1,33 @@
langcode: en
status: true
dependencies:
module:
- field_permissions
- file
- image
- taxonomy
third_party_settings:
field_permissions:
permission_type: public
id: taxonomy_term.field_license_icon
field_name: field_license_icon
entity_type: taxonomy_term
type: image
settings:
default_image:
uuid: null
alt: ''
title: ''
width: null
height: null
target_type: file
display_field: false
display_default: false
uri_scheme: public
module: image
locked: false
cardinality: 1
translatable: true
indexes: { }
persist_with_no_fields: false
custom_storage: false

31
entity_embed_attribution.default.licenses.yml

@ -0,0 +1,31 @@
---
-
title: Attribution 4.0 International (CC BY 4.0)
short_label: CC BY 4.0
icon_file: by.png
url: https://creativecommons.org/licenses/by/4.0/
-
title: Attribution-NonCommercial 4.0 International (CC BY-NC 4.0)
short_label: CC BY-NC 4.0
icon_file: by-nc.png
url: https://creativecommons.org/licenses/by-nc/4.0/
-
title: Attribution-NoDerivatives 4.0 International (CC BY-ND 4.0)
short_label: CC BY-ND 4.0
icon_file: by-nd.png
url: https://creativecommons.org/licenses/by-nd/4.0/
-
title: Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)
short_label: CC BY-SA 4.0
icon_file: by-sa.png
url: https://creativecommons.org/licenses/by-sa/4.0/
-
title: Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0)
short_label: CC BY-NC-ND 4.0
icon_file: by-nc-nd.png
url: https://creativecommons.org/licenses/by-nc-nd/4.0/
-
title: Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0)
short_label: CC BY-NC-SA 4.0
icon_file: by-nc-sa.png
url: https://creativecommons.org/licenses/by-nc-sa/4.0/

53
entity_embed_attribution.module

@ -10,7 +10,9 @@ use Drupal\Core\Url;
use Drupal\Core\Render\Markup; use Drupal\Core\Render\Markup;
use Drupal\Core\Entity\Entity\EntityFormDisplay; use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\Core\Entity\Entity\EntityViewDisplay; use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\taxonomy\Entity\Term;
use Drupal\file\Entity\File;
use Drupal\Component\Serialization\Yaml;
/** /**
* Implements hook_help(). * Implements hook_help().
@ -67,6 +69,9 @@ function entity_embed_attribution_modules_installed($modules) {
'settings' => ['view_mode' => 'default', 'link' => ''], 'settings' => ['view_mode' => 'default', 'link' => ''],
])->save(); ])->save();
} }
// Load default license terms from the module config.
entity_embed_attribution_load_default_licenses();
} }
/** /**
@ -76,7 +81,8 @@ function entity_embed_attribution_modules_installed($modules) {
*/ */
function entity_embed_attribution_preprocess_entity_embed_container(&$variables) { function entity_embed_attribution_preprocess_entity_embed_container(&$variables) {
if ($attributions = $variables['element']['#entity']->get('field_image_attribution')->referencedEntities()) { if ($attributions = $variables['element']['#entity']->get('field_image_attribution')
->referencedEntities()) {
$attribution = $attributions[0]; $attribution = $attributions[0];
$author = $attribution->get('field_attribution_author')->getValue()[0]; $author = $attribution->get('field_attribution_author')->getValue()[0];
@ -114,11 +120,52 @@ function entity_embed_attribution_preprocess_entity_embed_container(&$variables)
} }
// $attribution_string = \Drupal::render($attribution_text); // $attribution_string = \Drupal::render($attribution_text);
$variables['children'] = ['first' => ['#type' => 'markup', '#markup' => render($variables['children'])], $variables['children'] = [
'first' => [
'#type' => 'markup',
'#markup' => render($variables['children'])
],
$attribution_text $attribution_text
]; ];
}
/**
* Read the list of pre-defined Creative Commons licenses and create corresponding taxonomy terms.
*/
function entity_embed_attribution_load_default_licenses() {
$file_path = drupal_get_path('module', 'entity_embed_attribution') . '/entity_embed_attribution.default.licenses.yml';
$file_contents = file_get_contents($file_path);
$license_data = Yaml::decode($file_contents);
foreach ($license_data as $license_item) {
entity_embed_attribution_create_license_term($license_item['title'],$license_item['short_label'], $license_item['icon_file'], $license_item['url']);
}
}
function entity_embed_attribution_create_license_term($term_title, $term_short_label, $icon_filename, $license_url) {
$icon_file_uri = drupal_get_path('module', 'entity_embed_attribution') . "/images/$icon_filename";
// Just in case the file has already been created.
$icon_files = \Drupal::entityTypeManager()
->getStorage('file')
->loadByProperties(['uri' => $icon_file_uri]);
$icon_file = reset($icon_files);
// if not create a file
if (!$icon_file) {
$icon_file = File::create([
'uri' => $icon_file_uri,
]);
$icon_file->save();
}
$tid = Term::create([
'name' => $term_title,
'vid' => 'licenses',
'field_license_link' => ['title' => $term_short_label, 'uri' => $license_url],
'field_license_icon' => [
'target_id' => $icon_file->id(),
'alt' => $term_title,
'title' => $term_title,
]
])->save();
} }

BIN
images/by-nc-nd.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

BIN
images/by-nc-sa.eu.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

BIN
images/by-nc-sa.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

BIN
images/by-nc.eu.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.1 KiB

BIN
images/by-nc.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

BIN
images/by-nd.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

BIN
images/by-sa.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

BIN
images/by.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
images/publicdomain.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

Loading…
Cancel
Save