Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creative Commons licenses #1234

Open
mjordan opened this issue Aug 1, 2019 · 10 comments
Open

Creative Commons licenses #1234

mjordan opened this issue Aug 1, 2019 · 10 comments
Labels
Type: enhancement Identifies work on an enhancement to the Islandora codebase

Comments

@mjordan
Copy link
Contributor

mjordan commented Aug 1, 2019

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
Copy link
Contributor

alxp commented Aug 1, 2019

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
Copy link
Contributor Author

mjordan commented Aug 1, 2019

@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
Copy link
Contributor

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
Copy link
Contributor

alxp commented Aug 1, 2019

@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
Copy link
Contributor Author

mjordan commented Aug 7, 2019

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

@DonRichards
Copy link
Member

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
Copy link
Contributor

seth-shaw-unlv commented Jul 7, 2020

@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
Copy link
Member

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
Copy link
Contributor

alxp commented Jul 11, 2020 via email

@kayakr
Copy link
Contributor

kayakr commented Aug 28, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: enhancement Identifies work on an enhancement to the Islandora codebase
Projects
Development

No branches or pull requests

8 participants