Make possible to respond to image derivative creation

Created on 27 January 2018, almost 7 years ago
Updated 28 August 2024, 4 months ago

Problem/Motivation

Sometimes we need to respond on new image derivative creation.

Steps to reproduce

  • Create an image style
  • Upload a new image
  • Call the uri of the new style
  • The derivative image is generated, but there's no way to react to this, like sending some HTTP request to another system to inform about the new derivative image creation

Proposed resolution

Introduce a new hook_image_derivative_created(string $original_uri, string $style, string $derivative_uri) that can be implemented by other modules that will handle the derivative image creation.

Remaining tasks

Accept and commit.

User interface changes

None.

Introduced terminology

None.

API changes

Introduces new hook_image_derivative_created(string $original_uri, string $style, string $derivative_uri).

Data model changes

None.

Release notes snippet

Introduce new hook_image_derivative_created(string $original_uri, string $style, string $derivative_uri).

✨ Feature request
Status

Needs work

Version

11.0 πŸ”₯

Component
Image systemΒ  β†’

Last updated 1 day ago

Created by

πŸ‡­πŸ‡ΊHungary tikaszvince

Live updates comments and jobs are added and updated live.
  • Needs change record

    A change record needs to be drafted before an issue is committed. Note: Change records used to be called change notifications.

  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • The Needs Review Queue Bot β†’ tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

    Consult the Drupal Contributor Guide β†’ to find step-by-step guides for working with issues.

  • Status changed to Needs review almost 2 years ago
  • πŸ‡³πŸ‡΄Norway efpapado

    The patch does apply on 10.1.x. Setting to Needs review and retesting.

  • πŸ‡³πŸ‡΄Norway efpapado

    I'm proposing another patch, which has (almost) the same code as yours, but on a different class: Instead of invoking the hook on ImageStyleDownloadController::deliver(), I invoke it on ImageStyle::createDerivative() to make sure that the hook is invoked also when the derivative is created by other methods (for example through the image_style_warmer module).

  • πŸ‡³πŸ‡΄Norway efpapado

    Fixed PHPCS problems.

  • Status changed to Needs work almost 2 years ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request β†’ as a guide.

    Adding a new api will require a change record. An example is usually very helpful.

    Issue summary should be updated to more clearly define the proposed solution and api change.

    Will also need test coverage of the api working

  • Merge request !9257Introduce hook_image_derivative_created. β†’ (Open) created by efpapado
  • Status changed to Needs review 4 months ago
  • πŸ‡³πŸ‡΄Norway efpapado

    Updated the patch for the 11.x branch, and created a draft change record.

  • Pipeline finished with Success
    4 months ago
    Total: 501s
    #258927
  • πŸ‡³πŸ‡΄Norway efpapado

    After some thought, I added another argument in the hook, which is the id of the image style. Although by default it can be derived from the derivative image uri, there can be cases where this is not possible (for example a custom implementation of an external file system like s3fs.)

    Updated also the change record.

  • Pipeline finished with Failed
    4 months ago
    Total: 6827s
    #259082
  • Status changed to Needs work 4 months ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Sending to NW for the open tags

    Issue summary update and test coverage

    Looking at the MR new api should be typehinted also.

  • Pipeline finished with Failed
    4 months ago
    Total: 546s
    #262994
  • Pipeline finished with Failed
    4 months ago
    Total: 108s
    #263004
  • Status changed to Needs review 4 months ago
  • πŸ‡³πŸ‡΄Norway efpapado

    Added type hints to api, added a test. Not sure about the issue summary update, isn't the change record enough?

  • Pipeline finished with Failed
    4 months ago
    Total: 109s
    #263006
  • Pipeline finished with Failed
    4 months ago
    Total: 136s
    #263009
  • Pipeline finished with Failed
    4 months ago
    Total: 901s
    #263011
  • Status changed to Needs work 4 months ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    No issue summary is separate from a CR. Recommend using default issue template

  • Status changed to Needs review 4 months ago
  • πŸ‡³πŸ‡΄Norway efpapado

    Is it ok now?

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Summary yes

    But tests are failing too btw.

  • πŸ‡³πŸ‡΄Norway efpapado

    Removed a useless assertion that was breaking the tests.

  • Pipeline finished with Failed
    4 months ago
    Total: 466s
    #266999
  • Status changed to Needs work 4 months ago
  • πŸ‡³πŸ‡΄Norway efpapado

    Setting it back to needs work, the tests are failing, although they succeed locally. I will investigate further...

Production build 0.71.5 2024