FEEDS CONDITIONAL TAMPER
========================

Extends the Feeds Tamper module with two plugins that conditionally skip a
feed item or a field value based on a configurable condition. The condition
is evaluated against any source field in the feed row, or against the field
value being tampered itself.


REQUIREMENTS
------------
- Drupal 10.2 or 11
- tamper (drupal/tamper)
- feeds_tamper (drupal/feeds_tamper ^2.0)


INSTALLATION
------------
1. Place the module at docroot/modules/custom/feeds_conditional_tamper/.
2. Enable it:
     ddev drush en feeds_conditional_tamper -y
3. Rebuild the cache:
     ddev drush cr


PLUGINS PROVIDED
----------------

Skip item on condition  (skip_item_on_condition)
  When the condition is TRUE, the entire feed row is dropped — the node (or
  other entity) is not created or updated for that row. Equivalent to the
  built-in "Required" plugin, but driven by a flexible comparison rather than
  a simple empty/not-empty check.

Skip value on condition  (skip_value_on_condition)
  When the condition is TRUE, only the current field value is cleared (set to
  NULL). The rest of the feed row continues to be processed normally — the
  node is saved, but that particular field is left empty.


CONDITION SETTINGS
------------------
Both plugins share the same configuration form:

  Condition source
    Which feed source field to evaluate. Select "— Current field value —" to
    test the value that is currently being tampered (i.e. the mapped field
    itself). Select any other source to cross-reference a different column in
    the same feed row.

  Operator
    Equals                       — exact string match
    Does not equal               — exact string non-match
    Contains                     — substring present
    Does not contain             — substring absent
    Matches regular expression   — PHP preg_match() returns true
    Does not match regex         — PHP preg_match() returns false
    Is empty                     — value is NULL, "", or []
    Is not empty                 — value is not NULL, "", or []

  Condition value
    The string to compare against. Not shown for "is empty" / "is not empty".
    For regex operators, enter a full PHP regex including delimiters and flags,
    e.g.:  /^draft$/i   or   /^\d{4}-\d{2}-\d{2}$/

  Case sensitive
    When checked, string comparisons (equals, contains, …) are case-sensitive.
    Hidden for regex operators — include the "i" flag in the pattern instead.
    Hidden for empty/not-empty operators.


STEPS TO USE
------------

Step 1 — Open the feed type's Tamper configuration
  a. Go to:  Structure > Feed types
  b. Click the feed type you want to configure.
  c. Click the "Tamper" tab (added by feeds_tamper).

Step 2 — Add a tamper plugin to the relevant source
  a. Find the source field you want to use as the trigger (or the field whose
     value you want to suppress).
  b. Click "+ Add tamper" next to that source.
  c. From the plugin list, choose:
       - "Skip item on condition"   — to drop the whole row
       - "Skip value on condition"  — to clear only this field
  d. Click "Add tamper".

Step 3 — Configure the condition
  a. Condition source:
       - Leave as "— Current field value —" if the condition should test the
         value of the source field the tamper is attached to.
       - Or select a different source field to cross-reference. For example,
         attach the tamper to "field_pdf_url" but set the condition source to
         "type" to decide based on the row's "type" column.
  b. Operator: choose the comparison type.
  c. Condition value: enter the string or regex to compare against.
  d. Case sensitive: check if the comparison should be case-sensitive.
  e. Click "Save".

Step 4 — Test the import
  Run the import against a small sample that includes both matching and
  non-matching rows to verify the expected behaviour:
    ddev drush feeds:import {feed_id} -y

  Check Results > Recent log messages for any Tamper-related warnings.


WORKED EXAMPLES
---------------

Example 1 — Skip rows where "status" is "draft"
  Source the tamper is attached to:  status  (or any source column)
  Plugin:                Skip item on condition
  Condition source:      status
  Operator:              Equals
  Condition value:       draft
  Case sensitive:        unchecked

  Result: any feed row where the "status" column equals "draft" (case-
  insensitive) is silently dropped; all other rows import normally.

Example 2 — Only import a PDF URL when the row type is "resource"
  Source the tamper is attached to:  pdf_url
  Plugin:                Skip value on condition
  Condition source:      type
  Operator:              Does not equal
  Condition value:       resource
  Case sensitive:        unchecked

  Result: for rows where "type" is not "resource", the pdf_url field is
  cleared before saving. The node is still imported; only the PDF URL is
  suppressed.

Example 3 — Skip rows with a malformed date
  Source the tamper is attached to:  event_date
  Plugin:                Skip item on condition
  Condition source:      — Current field value —
  Operator:              Does not match regular expression
  Condition value:       /^\d{4}-\d{2}-\d{2}$/

  Result: rows whose event_date value does not match YYYY-MM-DD are dropped.

Example 4 — Clear a field when it has no value in the feed
  Source the tamper is attached to:  field_subtitle
  Plugin:                Skip value on condition
  Condition source:      — Current field value —
  Operator:              Is empty

  Result: when the subtitle column is empty in the feed, the field is
  explicitly cleared on the node rather than leaving a stale value from a
  previous import. (Equivalent to the Feeds "Required" plugin but without
  dropping the whole item.)


EXECUTION ORDER
---------------
Tamper plugins on the same source run in the order they appear on the Tamper
tab. Drag-and-drop reordering is available in the feeds_tamper UI. Place a
conditional skip tamper before any transformation tampers (e.g. string
manipulation, date conversion) if you want to avoid processing values that
will ultimately be skipped.


TROUBLESHOOTING
---------------
The condition never triggers / always triggers
  - Double-check the Condition source selection. "— Current field value —"
    uses the value of the field the tamper is attached to; selecting a
    different source reads that column directly from the feed row.
  - For string comparisons, verify case sensitivity matches the feed data.
  - For regex patterns, test the pattern at regex101.com against a sample
    value before saving.

The regex pattern fails validation on save
  - The pattern must include delimiters: /pattern/ or #pattern# etc.
  - Escape forward slashes inside the pattern if using / as delimiter:
      /foo\/bar/  or use an alternative delimiter: #foo/bar#

Items are skipped but no log message appears
  - "Skip item on condition" silently removes the row from the parse result,
    matching Feeds core behaviour for other filter-type tampers. This is
    intentional; Feeds does not log individual skipped rows by default.
