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

added tokens to handle islandora > media operation #836

Merged
merged 4 commits into from
Jul 6, 2021

Conversation

wgilling
Copy link

@wgilling wgilling commented May 3, 2021

This adds the two tokens that relate to media from the previously created "islandora_tokens" made by @kayakr

JIRA Ticket: Islandora/documentation#1171

  • Other Relevant Links (Google Groups discussion, related pull requests, Release pull requests, etc.)
    The other part of the tokens (that was in the "ASU islandora_tokens" module) have been moved into a pull request on the controlled_access_terms module.

What does this Pull Request do?

Adds two tokens (well four if you count the deprecated aliases) that can output a Repository Item's media field_media_image value by using one of the tokens like "media-thumbnail-image:alt" and "media-thumbnail-image:url", or "media_thumbnail_image:alt" and "media_thumbnail_image:url"

A brief description of what the intended result of the PR will be and/or what problem it solves.
Anywhere tokens may be used in Drupal, this allows the output of a Repository Item's media field_media_image value

How should this be tested?

From the Metatag settings interface, adjust the configuration for a "Repository item" to add a field value that uses one of the new tokens. Save config.
Refresh the page for any Repository item that does have media and inspect the section to see if the new value is represented.

Additional Notes:

This branch and the identically named branch on controlled_access_terms together represent the entire set of tokens that were made in two separate islandora_tokens modules that were simultaneously invented for slightly different needs. The ASU one was mostly for populating the Google Scholar metatags.

Interested parties

@dannylamb, @Islandora/8-x-committers, @kayakr

@dannylamb
Copy link

I can test this now

islandora.tokens.inc Outdated Show resolved Hide resolved
@dannylamb
Copy link

dannylamb commented May 3, 2021

I can confirm that this works through the UI. I set my description metatag to [islandoratokens:media-file-thumbnail:alt] and can see that rendered out in the html header.

When playing wtih it via drush (which is foolishly what I did first), I ran into this:

bash-5.1# drush php:cli
Psy Shell v0.10.8 (PHP 7.4.15 — cli) by Justin Hileman
>>> $node = Drupal\node\Entity\Node::load(15);
=> Drupal\node\Entity\Node {#5187
     +in_preview: null,
     #nid: Drupal\Core\Field\FieldItemList {#5539},
     #uuid: Drupal\Core\Field\FieldItemList {#5545},
     #vid: Drupal\Core\Field\FieldItemList {#5551},
     #langcode: Drupal\Core\Field\FieldItemList {#5557},
     #type: Drupal\Core\Field\EntityReferenceFieldItemList {#5571},
     #revision_timestamp: Drupal\Core\Field\FieldItemList {#5583},
     #revision_uid: Drupal\Core\Field\EntityReferenceFieldItemList {#5589},
     #revision_log: Drupal\Core\Field\FieldItemList {#5677},
     #status: Drupal\Core\Field\FieldItemList {#5679},
     #uid: Drupal\Core\Field\EntityReferenceFieldItemList {#5686},
     #title: Drupal\Core\Field\FieldItemList {#5699},
     #created: Drupal\Core\Field\FieldItemList {#5706},
     #changed: Drupal\Core\Field\ChangedFieldItemList {#5713},
     #promote: Drupal\Core\Field\FieldItemList {#5720},
     #sticky: Drupal\Core\Field\FieldItemList {#5727},
     #default_langcode: Drupal\Core\Field\FieldItemList {#5734},
     #revision_default: Drupal\Core\Field\FieldItemList {#5740},
     #revision_translation_affected: Drupal\Core\Field\FieldItemList {#5746},
     #metatag: Drupal\metatag\Plugin\Field\MetatagEntityFieldItemList {#5752},
     #path: Drupal\path\Plugin\Field\FieldType\PathFieldItemList {#5754},
     #menu_link: Drupal\token\MenuLinkFieldItemList {#5756},
     #content_translation_source: Drupal\Core\Field\FieldItemList {#5758},
     #content_translation_outdated: Drupal\Core\Field\FieldItemList {#5772},
     #field_access_terms: Drupal\Core\Field\EntityReferenceFieldItemList {#5777},
     #field_alternative_title: Drupal\Core\Field\FieldItemList {#5896},
     #field_classification: Drupal\Core\Field\FieldItemList {#5898},
     #field_coordinates: Drupal\Core\Field\FieldItemList {#5900},
     #field_coordinates_text: Drupal\Core\Field\FieldItemList {#5902},
     #field_description: Drupal\Core\Field\FieldItemList {#5904},
     #field_dewey_classification: Drupal\Core\Field\FieldItemList {#5950},
     #field_display_hints: Drupal\Core\Field\EntityReferenceFieldItemList {#5952},
     #field_edition: Drupal\Core\Field\FieldItemList {#6062},
     #field_edtf_date: Drupal\Core\Field\FieldItemList {#6064},
     #field_edtf_date_created: Drupal\Core\Field\FieldItemList {#6066},
     #field_edtf_date_issued: Drupal\Core\Field\FieldItemList {#6068},
     #field_extent: Drupal\Core\Field\FieldItemList {#6070},
     #field_genre: Drupal\Core\Field\EntityReferenceFieldItemList {#6077},
     #field_geographic_subject: Drupal\Core\Field\EntityReferenceFieldItemList {#6079},
     #field_identifier: Drupal\Core\Field\FieldItemList {#6081},
     #field_isbn: Drupal\Core\Field\FieldItemList {#6083},
     #field_language: Drupal\Core\Field\EntityReferenceFieldItemList {#6085},
     #field_lcc_classification: Drupal\Core\Field\FieldItemList {#6087},
     #field_linked_agent: Drupal\Core\Field\EntityReferenceFieldItemList {#6089},
     #field_local_identifier: Drupal\Core\Field\FieldItemList {#6091},
     #field_member_of: Drupal\Core\Field\EntityReferenceFieldItemList {#6093},
     #field_model: Drupal\Core\Field\EntityReferenceFieldItemList {#6106},
     #field_note: Drupal\Core\Field\FieldItemList {#6119},
     #field_oclc_number: Drupal\Core\Field\FieldItemList {#6121},
     #field_physical_form: Drupal\Core\Field\EntityReferenceFieldItemList {#6123},
     #field_pid: Drupal\Core\Field\FieldItemList {#6125},
     #field_place_published: Drupal\Core\Field\FieldItemList {#6127},
     #field_resource_type: Drupal\Core\Field\EntityReferenceFieldItemList {#6129},
     #field_rights: Drupal\Core\Field\FieldItemList {#6142},
     #field_subject: Drupal\Core\Field\EntityReferenceFieldItemList {#6144},
     #field_subjects_name: Drupal\Core\Field\EntityReferenceFieldItemList {#6157},
     #field_table_of_contents: Drupal\Core\Field\FieldItemList {#6159},
     #field_temporal_subject: Drupal\Core\Field\EntityReferenceFieldItemList {#6161},
     #field_weight: Drupal\Core\Field\FieldItemList {#6163},
   }
>>> \Drupal::service('token')->replace('Hello World [islandoratokens:media-thumbnail-image:url]', ['node' => $node]);
PHP Notice:  Undefined variable: islandoraUtils in /var/www/drupal/web/modules/contrib/islandora/islandora.tokens.inc on line 69
PHP Error:  Call to a member function getTermForUri() on null in /var/www/drupal/web/modules/contrib/islandora/islandora.tokens.inc on line 69
>>> 

Admittedly this probably isn't that big of a deal. Just reporting it because I bumped into it.

* @return mixed
* \Drupal\file\FileInterface on success, NULL otherwise.
*/
function controlled_access_terms_image_from_media($media) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably can ditch this for the MediaSourceService, but if not, you'd wanna rename it :)

@dannylamb
Copy link

Testing again @wgilling

Copy link

@dannylamb dannylamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error I was getting in Drush is gone. Thx @wgilling. There's two small things to touch up and I'm happy to merge this in.

$replacements = [];
if ($type == 'islandoratokens' && !empty($data['node'])) {
if (!is_array($tokens) || empty($tokens)) {
\Drupal::logger('controlled_access_terms')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

controlled_access_terms should be islandora here.

// Is there media?
// @todo: is this single or multiple?
if ($media) {
$file = controlled_access_terms_image_from_media($media);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can replace this with

$file = \Drupal::service('islandora.media_source_service')->getSourceFile($media);

and delete the controlled_access_terms_image_from_media function altogether.

… removed the controlled_access_terms_image_from_media method
@wgilling
Copy link
Author

wgilling commented May 6, 2021

ok - as per the most recent two requested changes, I pushed a commit to update the logger type and replace the controlled_access_terms_image_from_media method call (as well as remove that method's code).

@wgilling
Copy link
Author

@dannylamb -- is there something that is still not addressed for this?

@dannylamb
Copy link

spinning this up again 🚀

@dannylamb
Copy link

Tested again and the token's are replacing fine 🚀

phpcs is complaining at you, but looks like phpcbf can fix all the issues automatically. Run phpcbf and push up those changes and we can merge.

@wgilling
Copy link
Author

wgilling commented Jun 1, 2021

that should do it @dannylamb ... it's been a pleasure.

@elizoller
Copy link
Member

@dannylamb can this be merged?

@dannylamb
Copy link

Yes, yes it can. Thanks for the nudge. This was one I was really hoping to get in for the release. I'll add an entry for it in our test case spreadsheet and go through the motions again after merging.

@dannylamb dannylamb merged commit 8a28ea2 into Islandora:8.x-1.x Jul 6, 2021
@dannylamb
Copy link

Thanks for all your work on this @wgilling , this opens up a lot of new ground for us.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants