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

Uploaded File replacement functionality (in File & Media fields) #89

Closed
macburgee1 opened this issue Jul 3, 2019 · 3 comments
Closed

Comments

@macburgee1
Copy link
Contributor

macburgee1 commented Jul 3, 2019

Here's a core issue: https://www.drupal.org/project/drupal/issues/2648816. There's been nothing meaningful happening there - no patches have been offered since the issue was opened in Jan 2016.

This module will take advantage of a proposed hook_file_upload() function: https://www.drupal.org/project/drupal/issues/3065698.

@macburgee1
Copy link
Contributor Author

Let's take a look at the new Media Entity File Replace module. It sidesteps a number of issues I was running into.

In my initial testing, it works as I expected. Because it can only act on the edit form (and not on the add form), it shouldn't be possible to overwrite a file accidentally (e.g. file with same name already exists on another media entity.)

We'll need to figure out the external cache piece, however.

@macburgee1
Copy link
Contributor Author

See code example from https://www.drupal.org/project/acquia_purge/issues/2911828#comment-12450381:

/**
 * Implements hook_entity_update().
 */
function my_module_entity_update(EntityInterface $entity) {
  $type = $entity->getEntityTypeId();
  if ($type != 'file') {
    return;
  }

  $purgeInvalidationFactory = \Drupal::service('purge.invalidation.factory');
  $purgeQueuers = \Drupal::service('purge.queuers');
  $purgeQueue = \Drupal::service('purge.queue');

  $queuer = $purgeQueuers->get('coretags');
  // Invalidate cache tags so all pages that have the file get banned from varnish
  // Also invalidate the file's url.
  $invalidations = [
    $purgeInvalidationFactory->get('tag', 'file:' . $entity->id()),
    $purgeInvalidationFactory->get('url', file_create_url($entity->getFileUri())),
  ];

  $purgeQueue->add($queuer, $invalidations);
}

It would be nice if the Media Entity File Replace module provided a hook for us to use as a trigger. That said, in media_entity_file_replace_entity_extra_field_info(), they check if $mediaType->getSource() instanceof File. If we can access that information from $entity, that would be a reasonable solution.

@ericras
Copy link
Member

ericras commented Mar 22, 2023

Media Entity File Replace added: 73fedef

That takes care of media file entities. Still an issue with plain file fields. Will will be using those? Direct devs who create custom content types to use media files?

Wiki started to contain these notes: https://github.com/unlcms/project-herbie/wiki/Site-Developer-Role-Notes

@ericras ericras changed the title Create custom module to add uploaded file replacement functionality Uploaded File replacement functionality (in File & Media fields) Mar 22, 2023
@ericras ericras closed this as completed Apr 7, 2023
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

No branches or pull requests

2 participants