"Rewrite" plugin doesn't work right

Created on 23 November 2022, over 2 years ago
Updated 17 July 2025, 20 days ago

Problem/Motivation

I'm trying to rewrite the value of a phone number and the "Rewrite" plugin doesn't seem to work correctly.

The number comes in the format "123/456-7890". I'm trying to rewrite it to "(123)456-7890". I have a field in the feed called "WORK_PHONE". I have one plugin that replaces the slash with a close bracket, that works correctly. I added a Rewrite plugin to prepend the open bracket, so the replacement value is set to "([WORK_PHONE]". When the data imports all of the phone numbers end up with the value"([WORK_PHONE]" instead of the expected "(123)456-7890", i.e.

Steps to reproduce

Add a Rewrite plugin that includes the value being processed, e.g. on a field "SOMETHING" set the replacement string to be "The new string is [SOMETHING]."

Proposed resolution

Fix the problem so that in the example above if the value was "mango" the output would be "The new string is mango."

Remaining tasks

Work out the source of the problem.
Fix the problem.

User interface changes

n/a

API changes

TBD

Data model changes

n/a

πŸ› Bug report
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States damienmckenna NH, USA

Live updates comments and jobs are added and updated live.
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.

  • @megachriz opened merge request.
  • @megachriz opened merge request.
  • πŸ‡³πŸ‡±Netherlands megachriz

    I think that the issue actually is in Feeds Tamper:

    1. Say you have a source item with the following data:
      [
        'phone' => '123/456-7890',
      ]
      
    2. On the source "phone", you apply the Tamper "find_replace", replacing / with )
    3. Also on the source "phone", you apply the Tamper "rewrite", with the following text: ([phone]

    With Feeds, the result becomes:

    [
      'phone' => '(123/456-7890',
    ]
    

    That's because Feeds Tamper now writes the result back to the source at the end of the chain and not in between.

    • Branch 3323381-rewrite-tests_only changes ChainedTamperTest to mimic Feeds Tamper's current behavior.
    • Branch 3323381-rewrite-test-updated changes ChainedTamperTest to mimic what Feeds Tamper's behavior probably should be.
  • πŸ‡³πŸ‡±Netherlands megachriz
    • megachriz β†’ committed f4a5e23b on 8.x-1.x
      Issue #3323381 by megachriz: Added test coverage for using the Rewrite...
  • πŸ‡³πŸ‡±Netherlands megachriz

    Moving this to Feeds Tamper now.

  • πŸ‡³πŸ‡±Netherlands megachriz

    I've provided a fix and I've updated the issue summary to clarify what the problem is.

  • Merge request !24Resolve #3323381 "Update item" β†’ (Open) created by megachriz
Production build 0.71.5 2024