Wrong param type in hook job after request translation

Created on 27 February 2023, over 1 year ago
Updated 21 October 2023, about 1 year ago

Problem/Motivation

Hello everyone,

When I tried to use the "tmgmt job after request translation" hook, I got an error about the function parameter type.

I noticed that it was an array of jobs and not a job object.

Here is a patch that may solve the problem.

Have a nice day.

🐛 Bug report
Status

Needs work

Version

1.14

Component

Core

Created by

🇧🇪Belgium gilles_webstanz

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @gilles_webstanz
  • Issue was unassigned.
  • Status changed to Needs work about 1 year ago
  • 🇨🇭Switzerland berdir Switzerland

    That is indeed wrong, but it's actually job items, not jobs. See \Drupal\tmgmt\Entity\Job::requestTranslation(). And the @param type should not be array but class[]

  • 🇧🇪Belgium gilles_webstanz

    Hello @berdir,

    Thank you for your help !

    Here a new patch...

    Hope it's good..

  • 🇨🇭Switzerland berdir Switzerland
    1. +++ b/tmgmt.api.php
      @@ -281,16 +281,19 @@ function hook_tmgmt_job_before_request_translation(JobInterface $job) {
      - * @param \Drupal\tmgmt\JobInterface $job
      + * @param JobInterface[] $job_items
        *   The Job being submitted.
        */
      -function hook_tmgmt_job_after_request_translation(JobInterface $job) {
      +function hook_tmgmt_job_after_request_translation($job_items)
      +{
         /** @var \Drupal\tmgmt\Data $data_service */
      

      types in @param definitions need to use full namespace, and the { must be on the same line.

    2. +++ b/tmgmt.api.php
      @@ -281,16 +281,19 @@ function hook_tmgmt_job_before_request_translation(JobInterface $job) {
       
         // Reset the previous done changes to the data for example.
      -  foreach ($job->getItems() as $job_item) {
      -    $unfiltered_data = $job_item->getData();
      +  foreach ($job_items as $job) {
      +    // Reset the previous done changes to the data for example.
      +    /** @var JobInterface $job */
      +    $unfiltered_data = $job->getData();
      

      $job is also a $job_item now, not a $job, the only thing that needs to change about the loop is that it's just $job_items as and not $job->getItems() as.

    3. +++ b/tmgmt.api.php
      diff --git a/wrong-param-type-in-hook-job-after-request-translation-4.patch b/wrong-param-type-in-hook-job-after-request-translation-4.patch
      index 9c9ec99..e69de29 100644
      
      index 9c9ec99..e69de29 100644
      --- a/wrong-param-type-in-hook-job-after-request-translation-4.patch
      
      --- a/wrong-param-type-in-hook-job-after-request-translation-4.patch
      +++ b/wrong-param-type-in-hook-job-after-request-translation-4.patch
      
      +++ b/wrong-param-type-in-hook-job-after-request-translation-4.patch
      +++ b/wrong-param-type-in-hook-job-after-request-translation-4.patch
      @@ -1,35 +0,0 @@
      
      @@ -1,35 +0,0 @@
      -diff --git a/tmgmt.api.php b/tmgmt.api.php
      -index 971dec0..e810160 100644
      ---- a/tmgmt.api.php
      -+++ b/tmgmt.api.php
      -@@ -281,19 +281,23 @@ function hook_tmgmt_job_before_request_translation(JobInterface $job) {
      - /**
      -  * Allows to alter job checkout workflow after the default behavior.
      

      your patch includes a patch file.

Production build 0.71.5 2024