Islandora / documentation

Contains islandora's documentation and main issue queue.
MIT License
103 stars 71 forks source link

Creative Commons licenses #1234

Open mjordan opened 5 years ago

mjordan commented 5 years ago

Looks like the Creative Commons contrib module for Drupal 8 is stalled. CC licenses are something SFU needs to have before we can migrate out IR to Islandora 8, since we used the D6 version of the module extensively (our IR is a D6 site).

I am thinking it would be possible to implement the ability to use CC licenses (and maybe others) as a taxonomy (conveniently, each CC license has a URI - nice). I am happy to take a stab at a proof of concept.

alxp commented 5 years ago

I made this module for another project outside of Islandora but it might be something we can adapt for our needs here. One thing is that it attaches to media directly and not to nodes, which might be something we'd want to change

https://www.drupal.org/project/media_attribution

mjordan commented 5 years ago

@alxp heh, great minds think alike. I agree, the node is the preferred entity, but it would be very useful to allow both types of entity to have licenses. I'll give the module a spin before next week (at a conference now and may not have net access over the next few eays).

Natkeeran commented 5 years ago

We can extend that to any type of right statement. However, we may need a way to qualify the type or source: https://rightsstatements.org/en/

alxp commented 5 years ago

@mjordan I can make you a co-maintainer if you like, it was specifically made to let you print an attribution below a media as it's used in e.g. an article, but it does a nice job of populating a taxonomy with the CC licenses with appropriate images which can be added to with other licenses.

mjordan commented 5 years ago

@alxp thanks for the offer but I am overextended as it is.

DonRichards commented 4 years ago

I hope the interest for this hasn't stalled but I think this would be highly useful. I'm not sure how complete @alxp solution is but there's some interest from us on this.

seth-shaw-unlv commented 4 years ago

@DonRichards

We simply use a Link field that includes the URI of the rights statement as the link value and the term for the link label.... but we batch load these records right now, so entering values isn't troublesome. We may create a widget with a drop-down list of available rights statements. Addendum: one of the reasons we like this solution is that the JSON-LD uses the URL for the rights statement instead of a taxonomy-term surrogate URL.

Another option is to create a rights statement taxonomy and then create a formatter that use's the term's field_external_authority, or whatever the URI field is, to create a link on the node's page:

<?php

namespace Drupal\islandora_local\Plugin\Field\FieldFormatter;

use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\Plugin\Field\FieldFormatter\EntityReferenceFormatterBase;
use Drupal\link\LinkItemInterface;
use Drupal\Core\Form\FormStateInterface;

/**
 * Plugin implementation of the 'LinkedEntityLink'.
 *
 * @FieldFormatter(
 *   id = "linked_entity_link",
 *   label = @Translation("Linked Entity Link"),
 *   field_types = {
 *     "entity_reference"
 *   }
 * )
 */
class LinkedEntityLink extends EntityReferenceFormatterBase {

  /**
   * {@inheritdoc}
   */
  public static function defaultSettings() {
    return [
      'link_field' => '',
    ] + parent::defaultSettings();
  }

  /**
   * {@inheritdoc}
   */
  public function settingsForm(array $form, FormStateInterface $form_state) {
    $settings = $this->getSettings();
    $link_fields = [];
    foreach (\Drupal::entityManager()->getFieldMap() as $entity_type => $fields) {
      foreach ($fields as $field_name => $field_info) {
        if ($field_info['type'] === 'link') {
          $link_fields[$field_name] = $field_name;
        }
      }
    }
    $element['link_field'] = [
      '#type' => 'select',
      '#title' => t('Link Field'),
      '#options' => $link_fields,
      '#required' => TRUE,
      '#default_value' => $settings['link_field'],
    ];
    return $element;
  }

  /**
   * {@inheritdoc}
   */
  public function viewElements(FieldItemListInterface $items, $langcode) {
    $element = [];
    foreach ($this->getEntitiesToView($items, $langcode) as $delta => $entity) {
      try {
        $field = $entity->get($this->getSetting('link_field'));

        if (!empty($field)) {
          foreach ($entity->get('field_project_site_url') as $delta2 => $item) {
            $link_title = $entity->label();
            $url = $this->buildUrl($item);

            $element[$delta] = [
              '#type' => 'link',
              '#title' => $link_title,
            ];
            $element[$delta]['#url'] = $url;
            if (!empty($item->_attributes)) {
              $element[$delta]['#options'] += [
                'attributes' => [],
              ];
              $element[$delta]['#options']['attributes'] += $item->_attributes;

              // Unset field item attributes since they have been included in the
              // formatter output and should not be rendered in the field template.
              unset($item->_attributes);
            }
          }
        }
        else {
          $element[$delta] = $entity->toLink()->toRenderable();
        }
      }
      catch (\InvalidArgumentException $e) {
        \Drupal::logger('islandora_local')->warning('LinkedEntityLink attempted to use an invalid field: ' . $e->getMessage());
        $element[$delta] = $entity->toLink()->toRenderable();
      }
    }

    return $element;

  }

  /**
   * Builds the \Drupal\Core\Url object for a link field item.
   *
   * Stolen from Drupal\link\Plugin\Field\FieldFormatter, which we don't extend.
   *
   * @param \Drupal\link\LinkItemInterface $item
   *   The link field item being rendered.
   *
   * @return \Drupal\Core\Url
   *   A Url object.
   */
  protected function buildUrl(LinkItemInterface $item) {
    $url = $item
      ->getUrl() ?: Url::fromRoute('<none>');
    $options = $item->options;
    $options += $url
      ->getOptions();

    $url
      ->setOptions($options);
    return $url;
  }

}

_Note: if the target term doesn't have a value in the configured field this module will just build a link to the current node, which should be fixed, but I haven't gotten around to it... it also assumes the existence of a field_project_site_url which should be fixed before this formatter is ready for general use... but this could is a starting point for someone at least. Fixed._

We use this little plugin for a digital projects vocabulary where some of the digital projects have their own sites so users will be redirected to the relevant site instead of to the taxonomy term page. It would also work for rights statements (after some tweaking) if you want to direct people to the relevant rights statement page rather than to the rights statement taxonomy term page.

elizoller commented 4 years ago

We use an entity reference field to a taxonomy for reuse permissions. The taxonomy contains fields for the link and an image. Then we're using a custom template to handle the display so it renders the CC image as a link to the CC license.

alxp commented 4 years ago

I made a module for attaching an attribution to media items you embed in to content via CKEditor. It includes a list of CC licenses in a taxonomy vocabulary that gets bulk-loaded on installation from a YML file.

We ended up making use of the module without the media embed part for the RDM project just to have an easy way to bulk load licenses. You just need to specify the short name, long description, image URL and license definition URL in the YML file to include it or create one when the module is installed.

https://www.drupal.org/project/media_attribution https://www.drupal.org/project/media_attribution

On Jul 10, 2020, at 4:13 PM, Eli Zoller notifications@github.com wrote:

We use an entity reference field to a taxonomy for reuse permissions. The taxonomy contains fields for the link and an image. Then we're using a custom template to handle the display so it renders the CC image as a link to the CC license.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Islandora/documentation/issues/1234#issuecomment-656845980, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAUD3FDE6BBDRWWR3LMWPLR25R5BANCNFSM4IIRCTUA.

kayakr commented 2 weeks ago

FYI, I have a module at https://www.drupal.org/project/cca_rights that creates CC and Rights Statements terms useful to reference from a Repository Item rights field.