0

I’m trying to migrate some data from a remote rest/api (json) using the plugin source url. My problem is in the json i consume the image name field comes with an incorrect value.

In imageName comes '0_3.jpg' and the correct name is '0_3.png', for example

So i have the following code trying to transform the name:

  source_full_path:
    -
      plugin: concat
      delimiter: /
      source:
        - constants/source_base_path
        - imageName:
            plugin: str_replace
            source: imageName
            search: "jpg"
            replace: "png"

but this gives the following error:

TypeError: Argument 2 passed to Drupal\Component\Utility\NestedArray::getValue() must be of the type array, null given

Anyone has any idea?

1

Two options:

_image_fixed:
  - plugin: str_replace
    source: imageName
    search: "jpg"
    replace: "png"

source_full_path:
  - plugin: concat
    delimiter: /
    source:
      - constants/source_base_path
      - @_image_fixed

Or:

source_full_path:
  - plugin: concat
    delimiter: /
    source:
      - constants/source_base_path
      - imageName
  - plugin: str_replace
    search: "jpg"
    replace: "png"
  • your solutions work perfectly. thanks! – leandro713 Mar 15 at 9:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.