Columbus, Ohio
Account created on 21 September 2015, over 9 years ago
#

Merge Requests

Recent comments

πŸ‡ΊπŸ‡ΈUnited States patrickfweston Columbus, Ohio

I rolled the changes from the https://www.drupal.org/project/restrict_by_ip/issues/3292104’ issue onto the MR for this. Additionally, this fork is a commit behind the upstream repository, so I applied that update as well.

This patch applies cleanly to the current version of 8.x-4.x (with hash 0092bb6).

Testing the functionality locally is working as expected for me.

πŸ‡ΊπŸ‡ΈUnited States patrickfweston Columbus, Ohio

I was actually able to get a proof of concept working where the path alias of the media entity is used, but the image content is displayed inline in the browser.

Here's what my EventSubscriber looks like:

  public function onRequest(RequestEvent $event) {
    // Get values from the request.
    $attributes = $event->getRequest()->attributes;
    $media = $attributes->get('media');
    $route_name = $attributes->get('_route');

    // Redirect to the file directly if we are accessing a media entity's full
    // view mode route.
    $view_mode = $attributes->get("view_mode");
    if ($media && !str_contains($route_name, 'media_entity_download') && $route_name && $view_mode === 'full') {
      // Get the source for this media entity.
      $source = $media->getSource();

      // Grab the ID values from the source information to be fetched from the
      // Acquia DAM.
      $id_values = $source->getSourceFieldValue($media);

      // Get the client for the Acquia DAM and get the asset object.
      $client = \Drupal::service('acquia_dam.client.factory')->getSiteClient();
      $asset = $client->getAsset($id_values['asset_id'], $id_values['version_id'] ?? '');

      // Get the embed URL for the asset.
      $url = $asset["embeds"]["original"]["url"];

      // Create a response with the URL's content.
      $response = new Response(file_get_contents($url));

      // Create the disposition of the file to display it inline.
      $disposition = $response->headers->makeDisposition(
        ResponseHeaderBag::DISPOSITION_INLINE,
        $asset['filename']
      );

      // Create the MIME type from the Asset's properties.
      $mime_type = $asset["file_properties"]["format_type"] . "/" . $asset["file_properties"]["format"];

      // Initialize headers for the response.
      $headers = [
        'Content-Type' => $mime_type,
        'Content-Disposition' => $disposition . '"',
        'Content-Description' => ' File Transfer',
      ];

      // Return the response object.
      $response->headers->add($headers);
      $response->setStatusCode(Response::HTTP_OK);

      // Dispatch request
      $event->setResponse($response);
    }
  }
πŸ‡ΊπŸ‡ΈUnited States patrickfweston Columbus, Ohio

This would be really great to get merged in. I've created a patch for our project to provide URLs with itok values for images with styles. We were seeing that the image styles were not getting cleared in cache.

The approach in this branch using wildcards is a much better solution.

I've included my patch if folks are curious. However, when I get time, I'll be switching our codebase over to the wildcard approach.

πŸ‡ΊπŸ‡ΈUnited States patrickfweston Columbus, Ohio

I was unable to get image style derivatives successfully cleared out of the Varnish cache using this module out of the box.

I've attached a patch that extends this module's code to also check for the existence of image style files, adding them to the set of URLs to be invalidated in Varnish.

Since I'm unable to confirm if this issue is widespread or specific to my site, I'm not going to create a new issue for this. However, I thought the patch could be helpful to folks who may encounter the same issue.

πŸ‡ΊπŸ‡ΈUnited States patrickfweston Columbus, Ohio

I'm having an issue getting image styles cleared out on update. I have media entities using a File field instead of an Image field, and I'm wondering if this is part of the reason I'm not seeing styles get flushed.

I'm going to do some experimentation and see how I can get this to work.

Production build 0.71.5 2024