Problem/Motivation

Some entity types, like the entity type "OG Membership" has properties of type "entity". Entering a default value for this property on the processor settings page can't be done as the field for it shows as a text field. Filling in any value results into validation errors, as the Entity API expects a value of type EntityMetadataWrapper for this property type. In case of the entity type "OG Membership" this is a extra hurdle, as the property of type "entity" is also required. As a result, the settings for the processor cannot be saved.
The same issue applies when mapping to a property of this type.

Proposed resolution

Introduce a new plugin type, called "Feeds entity processor property". Plugins of this type should do the following:

  • Provide a field to be used on the "Default values" section.
  • Validate values from the "Default values" section.
  • Provide a mapping target.
  • Set a value on the mapping target.

For each property type which Feeds entity processor property plugin should be used can be specified (in code). If none is specified, there will be a fallback to a default plugin.

The property type "entity" will have its own plugin to convert values to a EntityMetadataWrapper object and to display two fields on the "Default values" section: one for entity type and one for entity ID.

Remaining tasks

Manual testing.

User interface changes

The fields shown on the "Default values" section on the processor settings page may change depending on which entity processor is being used. Mappers for properties of type "entity" will get a mapping option for setting the entity's type.

API changes

A new API called "Feeds entity processor property" will be introduced. A hook called hook_feeds_entity_processor_properties() will be added. With this hook you can specify which plugin to use for which property type.

Data model changes

None.

Patch will follow.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

MegaChriz created an issue. See original summary.

MegaChriz’s picture

Here is a first step at this, with automated tests included. Tested manually with importing OG memberships where I only mapped to "Group" and "Entity".

I used the following values in the "Default values" section on the processor settings:

  • Entity type: user
  • Group_type: Node
  • State: Active
  • Field_name: og_user_node
  • OG Group: Entity type: Node
  • OG Group: Entity ID: 2
  • Entity: Entity type: User
  • Entity: Entity ID: 1

Additionally I created a group node which ID was 2.

The "Group" and "Entity" that you specify in the "Default values" section have to exist.

This how an entity can be specified in the "Default values" section:

This is how you can map to a property of type "entity":

MegaChriz’s picture

The only issue I've found with the patch so far is the following: if you apply it and do not flush caches, you can get a fatal error "Class name must be a valid object or a string".

The attached patch fixes this by throwing a RuntimeException instead with the message that caches must be flushed.

  • MegaChriz committed 95b48d7 on 7.x-1.x
    Issue #2659900 by MegaChriz: added Feeds entity processor property API...
MegaChriz’s picture

Status: Needs review » Fixed

Committed #3.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.