Skip to content
This repository has been archived by the owner on Aug 18, 2020. It is now read-only.

Content modeling overhaul #23

Merged

Conversation

dannylamb
Copy link
Contributor

GitHub Issue: Part of this monstrosity: Islandora/documentation#86

What does this Pull Request do?

Adds an action to generate image derivatives. Packages up default config as a feature.

What's new?

Said action and feature.

How should this be tested?

Tested as part of Islandora/documentation#86

Interested parties

@Islandora-CLAW/committers

$source_media = $this->utils->getMediaWithTerm($entity, $source_term);
$source_field = $this->mediaSource->getSourceFieldName($source_media->bundle());
$files = $source_media->get($source_field)->referencedEntities();
$file = reset($files);
Copy link
Contributor

Choose a reason for hiding this comment

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

Field references always confuse me a bit but does this mean each field can only reference a single entity? If so, is this a choice or no other alternatives worked and lastly if so, we should document it so when people create their own objects they don't try to link multiple objects to the same field.

Choose a reason for hiding this comment

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

This is a complex pull to review and I'm most likely getting 10% here : so who triggers the derivative here? Comment

// Find media belonging to node that has the source term, and get its file url.

makes understand that the node via a taxonomy term, or it is the media entity via a taxonomy term or both? Since Drupal is Drupal (deep thinking of mine), and media entities can be referenced by any many other ways outside the islandora scope, N nodes to 1 Media entity is possible right?

So a using a taxonomy term on a Node to define if the thumbnail gets generated would make things complicated, assuming node is the trigger. Thinking about how complicated derivative generation on 7.x even on a shallow single tree (one datastream can belong to a single object only) is, since we are already using the inline_entity_form which at least would make user experience good, would it make things easier that derivative is triggered by the media entity itself and bound to it?

and the any node that refers to that media entity gets (if the term for using the derivative is there) the existing derivative? Do i need more coffee?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it's a gross PR because of features and shuffling around / deleting tons of config. But you've both zeroed in on the right parts.

This bit in particular pulls out the file that the media is representing. That's why I'm assuming there's only one. This is pretty much the only place where that assumption is made, though. Generally speaking, any entity reference can have multiple values at pretty much any point in time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@DiegoPino If you wanna see where all that jazz happens, it's in entity hooks in islandora.module: https://github.com/dannylamb/islandora/blob/content-modeling-overhaul/islandora.module#L98

There's a few layers, but basically, in the hook you check to see if you should trigger derivitves at all (e.g. has the file actually changed?). If so it uses Context to evaluate conditions the user provides (e.g. Was it a Media that's a Preservation Master who belongs to an Image node that got updated?) Then it fires a ContextReaction that's a small wrapper around core Drupal actions like our indexing and un-indexing.

The actual generating of the message and publishing it to the queue is what this Action does.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh ok, so once you have a media entity we are assuming that each media entity references only one file? I'm okay with that assumption.

/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should there be a validation that the $form['mimetype'] doesn't have a non-image mimetype in it?

Choose a reason for hiding this comment

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

good catch, could probably we a select box to limit the options and the errors

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that's a good idea

Copy link

@DiegoPino DiegoPino left a comment

Choose a reason for hiding this comment

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

I really don't fully understand the logic yet, but added some comments

$source_media = $this->utils->getMediaWithTerm($entity, $source_term);
$source_field = $this->mediaSource->getSourceFieldName($source_media->bundle());
$files = $source_media->get($source_field)->referencedEntities();
$file = reset($files);

Choose a reason for hiding this comment

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

This is a complex pull to review and I'm most likely getting 10% here : so who triggers the derivative here? Comment

// Find media belonging to node that has the source term, and get its file url.

makes understand that the node via a taxonomy term, or it is the media entity via a taxonomy term or both? Since Drupal is Drupal (deep thinking of mine), and media entities can be referenced by any many other ways outside the islandora scope, N nodes to 1 Media entity is possible right?

So a using a taxonomy term on a Node to define if the thumbnail gets generated would make things complicated, assuming node is the trigger. Thinking about how complicated derivative generation on 7.x even on a shallow single tree (one datastream can belong to a single object only) is, since we are already using the inline_entity_form which at least would make user experience good, would it make things easier that derivative is triggered by the media entity itself and bound to it?

and the any node that refers to that media entity gets (if the term for using the derivative is there) the existing derivative? Do i need more coffee?


$parts = explode('#', $this->configuration['derivative_term_uri']);
if (count($parts) > 1) {
$name = $entity->id() . ' - ' . $parts[1];

Choose a reason for hiding this comment

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

$entity->uuid() to avoid collisions? Should it be the uuid of the media entity?(again, maybe not understanding this)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call. We might run into that on multisites.

/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {

Choose a reason for hiding this comment

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

good catch, could probably we a select box to limit the options and the errors

@whikloj
Copy link
Contributor

whikloj commented May 3, 2018

Also you are apparently already in need of a rebase. 😆

@dannylamb dannylamb mentioned this pull request May 3, 2018
@dannylamb
Copy link
Contributor Author

@whikloj @DiegoPino Ok, rebasing now. Just putting your review into this comment because they'll get dismissed when I force push.

I will use the uuid instead of the id for the default filename as per @DiegoPino's request.

I will do a form validation on mimetype to make sure its in the image/* family as per @whikloj 's request.

@dannylamb dannylamb force-pushed the content-modeling-overhaul branch from 272f031 to 64100e8 Compare May 10, 2018 17:31
@dannylamb
Copy link
Contributor Author

Ok, so these tests are passing locally, but will fail until Islandora/documentation#86 is merged due to dependencies.

Copy link
Contributor

@whikloj whikloj left a comment

Choose a reason for hiding this comment

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

I'm good here now. I'll wait till the Islandora PR is merged and re-start Travis to make sure we didn't miss anything.

@whikloj
Copy link
Contributor

whikloj commented Jun 5, 2018

Restarting travis

@whikloj
Copy link
Contributor

whikloj commented Jun 5, 2018

@dannylamb you have some code review stuff in here.
https://travis-ci.org/Islandora-CLAW/islandora_image/jobs/382270749#L820

@dannylamb
Copy link
Contributor Author

@whikloj @seth-shaw-unlv Travis is appeased.

@whikloj whikloj merged commit 4a19d3f into islandora-deprecated:8.x-1.x Jun 5, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants