Filters are used to change imported data before save or to validate data.

Edit filters

Edit filters that change data before entity is saved. You can specify multiple functions for one field, all calls will execute from
top to bottom.

  • Filter name - a name given by you for this filter. Must be unique in the same field context
  • Filter function - the name of the php function to apply on field value. You may also use a static function like this: ClassName::functionName. You can use any php or Drupal provided function. Also check our provided filters
  • Function params - params for php function (one per line). You can send the current field by using the placeholder specified in filter settings (this usually is [field]).

Explication of how filter work for above image:

Considering that initially TITLE = "this/is/the/title"

Apply strtoupper => TITLE = "THIS/IS/THE/TITLE"

Apply explode => TITLE = array("THIS", "IS", "THE", "TITLE") and this is the final value.

Edit pre-filters

Pre-filters are used to validate data. If a value doesn't pass pre-filters, next field path will be used if available.

In case of invalid content they must return an empty content: NULL, FALSE, empty string, empty array. 0 is not considered empty content. Otherwise it must return the input value (possibly altered).

The filters (described above) can use the prefiltered value by using as function FeedImportFilter::usePrefilteredValue or simply ::usePrefilteredValue.

Example of a pre-filter function:

I want to import only items with title starting with letter A. So I can make a functions that accepts as parameters the field and the letter.

  function is_starting_with_letter($field, $letter) {
    if ($field && $field[0] == $letter) {
      // The field starts with desired letter. return it to be available for other filter functions.
      return $field;
    }
    // It does not start with specified letter.
    return NULL;
  }

The params for this function will be (one per line): [field] and A.

Dynamic filters

Main purpose of these filter functions is testing. You can create php functions entering function name, args, and body as php code.

You can use these filters in Entity before/after combine callback, filters, pre-filters and in some cases in xpaths.

Import will not start if any of these functions have syntax errors.

If possible, please use a php file including filters (see Filter settings),
because if an error occurs on runtime in one of these functions the whole import script exits immediatly!

Filter settings

A filter class handles all filter process.

These settings are for the default filter: Feed Import filter. Modules can provide alternative filter classes.

  • Filter param placeholder - the placeholder used for field value, used in (pre-)filters
  • Include the following PHP files - you can include php files which contains only filter functions.
    In this way you don't have to change module to add a filter function or even worse to create a module only for providing filter functions.

    All paths to php files are relative to folder mentioned in description. If you want to use absolute paths use /

AttachmentSize
Edit filters57.11 KB
Dynamic filters109.04 KB
Filter settings40.03 KB