diff --git a/config/optional/core.entity_form_display.taxonomy_term.licenses.default.yml b/config/optional/core.entity_form_display.taxonomy_term.licenses.default.yml index 9801b16..d6af2f3 100644 --- a/config/optional/core.entity_form_display.taxonomy_term.licenses.default.yml +++ b/config/optional/core.entity_form_display.taxonomy_term.licenses.default.yml @@ -2,27 +2,45 @@ langcode: en status: true dependencies: config: + - entity_browser.browser.image_browser + - field.field.taxonomy_term.licenses.field_license_icon - field.field.taxonomy_term.licenses.field_license_link - taxonomy.vocabulary.licenses module: + - entity_browser - link - - path - text +_core: + default_config_hash: GeroQ_nB3tqP5g0Z5B4UShGyIomjdHA8hDn73kSFYgc id: taxonomy_term.licenses.default targetEntityType: taxonomy_term bundle: licenses mode: default content: description: - type: text_textfield - weight: 0 + type: text_textarea + weight: 3 region: content settings: - size: 60 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: { } field_license_link: - weight: 31 + weight: 1 settings: placeholder_url: '' placeholder_title: '' @@ -31,16 +49,11 @@ content: region: content name: type: string_textfield - weight: -5 + weight: 0 region: content settings: size: 60 placeholder: '' third_party_settings: { } - path: - type: path - weight: 30 - region: content - settings: { } - third_party_settings: { } -hidden: { } +hidden: + path: true diff --git a/config/optional/core.entity_view_display.taxonomy_term.licenses.default.yml b/config/optional/core.entity_view_display.taxonomy_term.licenses.default.yml new file mode 100644 index 0000000..de35ef8 --- /dev/null +++ b/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: { } diff --git a/config/optional/field.field.taxonomy_term.licenses.field_license_icon.yml b/config/optional/field.field.taxonomy_term.licenses.field_license_icon.yml new file mode 100644 index 0000000..28df4d0 --- /dev/null +++ b/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 Creative Commons..' +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 diff --git a/config/optional/field.storage.taxonomy_term.field_license_icon.yml b/config/optional/field.storage.taxonomy_term.field_license_icon.yml new file mode 100644 index 0000000..8432170 --- /dev/null +++ b/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 diff --git a/entity_embed_attribution.default.licenses.yml b/entity_embed_attribution.default.licenses.yml new file mode 100644 index 0000000..92f8dbf --- /dev/null +++ b/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/ \ No newline at end of file diff --git a/entity_embed_attribution.module b/entity_embed_attribution.module index 93085dc..3b88551 100644 --- a/entity_embed_attribution.module +++ b/entity_embed_attribution.module @@ -10,7 +10,9 @@ use Drupal\Core\Url; use Drupal\Core\Render\Markup; use Drupal\Core\Entity\Entity\EntityFormDisplay; use Drupal\Core\Entity\Entity\EntityViewDisplay; - +use Drupal\taxonomy\Entity\Term; +use Drupal\file\Entity\File; +use Drupal\Component\Serialization\Yaml; /** * Implements hook_help(). @@ -67,6 +69,9 @@ function entity_embed_attribution_modules_installed($modules) { 'settings' => ['view_mode' => 'default', 'link' => ''], ])->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) { - if ($attributions = $variables['element']['#entity']->get('field_image_attribution')->referencedEntities()) { + if ($attributions = $variables['element']['#entity']->get('field_image_attribution') + ->referencedEntities()) { $attribution = $attributions[0]; $author = $attribution->get('field_attribution_author')->getValue()[0]; @@ -112,13 +118,54 @@ 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 ]; +} +/** + * 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(); + } -} \ No newline at end of file + $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(); +} diff --git a/images/by-nc-nd.png b/images/by-nc-nd.png new file mode 100644 index 0000000..5a8dbd0 Binary files /dev/null and b/images/by-nc-nd.png differ diff --git a/images/by-nc-sa.eu.png b/images/by-nc-sa.eu.png new file mode 100644 index 0000000..433bc81 Binary files /dev/null and b/images/by-nc-sa.eu.png differ diff --git a/images/by-nc-sa.png b/images/by-nc-sa.png new file mode 100644 index 0000000..b9a5553 Binary files /dev/null and b/images/by-nc-sa.png differ diff --git a/images/by-nc.eu.png b/images/by-nc.eu.png new file mode 100644 index 0000000..efdb6af Binary files /dev/null and b/images/by-nc.eu.png differ diff --git a/images/by-nc.png b/images/by-nc.png new file mode 100644 index 0000000..25e2840 Binary files /dev/null and b/images/by-nc.png differ diff --git a/images/by-nd.png b/images/by-nd.png new file mode 100644 index 0000000..fc3d267 Binary files /dev/null and b/images/by-nd.png differ diff --git a/images/by-sa.png b/images/by-sa.png new file mode 100644 index 0000000..8770732 Binary files /dev/null and b/images/by-sa.png differ diff --git a/images/by.png b/images/by.png new file mode 100644 index 0000000..c8473a2 Binary files /dev/null and b/images/by.png differ diff --git a/images/publicdomain.png b/images/publicdomain.png new file mode 100644 index 0000000..df2c82f Binary files /dev/null and b/images/publicdomain.png differ