I've defined a shadowing callbacking in the entity-level properties map, e.g.

    // We want to populate field_dc_description from remote description.
    'field_dc_description' => array(
      'type' => 'text',
      'description' => 'Description of metadata record.',
      'remote property shadowing' => array(
        'remote to local callback' => 'fedoraentity_collection_shadow_remote_to_local',
      ),
    ),

but it doesn't get invoked. Looking at the logic in RemoteEntityAPIDefaultMetadataController->entityPropertyInfo() it's not clear that the 'remote property shadowing' key and associated data is ever passed through into the properties array for use in pack() and unpack().

Is this a bug or have I misinterpreted the documentation (see #2407659: More examples, documentation)?

Comments

jonathan_hunt’s picture

Issue summary: View changes
jonathan_hunt’s picture

Title: Does shadowing work? » Does shadowing work for Field API fields?

Ok, I mis-interpreted the docs. Instead of being a key on the entity-level properties map, shadowing can be specified via fedoraentity_entity_property_info_alter(). For example:

function mymodule_entity_property_info_alter(&$info) {
  if (!empty($info['fedoraentity'])) {
    $info['fedoraentity']['properties']['title']['remote property shadowing'] = array(
      'remote to local callback' => 'remote_entity_shadowing_schema_property_verbatim',
    );

    $info['fedoraentity']['properties']['description']['remote property shadowing'] = array(
      'remote to local callback' => 'remote_entity_shadowing_schema_property_verbatim_named',
      'local property' => 'field_dc_description',
    );
  }
}

This successfully populates the title and field_dc_description values into the first level of the entity array but it *doesn't* populate the default value of the field_dc_description (Field API field).

joachim’s picture

Status: Active » Postponed (maintainer needs more info)

> Does shadowing work for Field API fields?

As you've found, yes it does :)

> field_dc_description values into the first level of the entity array but it *doesn't* populate the default value of the field_dc_description (Field API field).

Do you mean that when you retrieve a remote entity and the 'description' remote property is empty, the locally-created entity doesn't get the default value for the field_dc_description that is set in Field admin? If you don't have the shadowing set, does that default value get set correctly?

jonathan_hunt’s picture

Status: Postponed (maintainer needs more info) » Active

To be clear, after importing an entity from remote, with shadowing per #2 the data structure is:

Array
(
    [14] => Entity Object
        (
// snipped
        [eid] => 14
        [remote_id] => collection:501
        [type] => collection
        [entity_data] => stdClass Object
            (
                [title] => My remote entity
                [type] => collection
                [description] => Insert something here about the remote entity...
                [id] => collection:501
                [remote_id] => collection:501
            )

        [created] => 1421358274
        [changed] => 0
        [remote_saved] => 0
        [needs_remote_save] => 0
        [expires] => 0
        [deleted] => 0
        [title] => My remote entity
        [field_dc_description] => Insert something here about the remote entity...

The shadowing callback has pulled title and description from entity_data but written them to the first level of the entity object. That's ok for title, since title is declared as a local property. But it is no good for field_dc_description which is a Field API text field. I would have expected field_dc_description to look more like

[field_dc_description] => Array(
  [und] => Array(
    [0] => Array(
      'value' => 'Insert something here about the remote entity...'
    )
  )
)

The field_dc_description value is not visible on entity view or edit pages.

This is why I asked whether shadowing works for Field API fields...

jonathan_hunt’s picture

Status: Active » Needs review
StatusFileSize
new637 bytes

Setting the incoming value on the entity wrapper rather than the entity directly works for properties and Field API fields.

Status: Needs review » Needs work

The last submitted patch, 5: remote_entity_shadowing_for_fieldapi_fields-2407677-5.patch, failed testing.

joachim’s picture

Title: Does shadowing work for Field API fields? » shadowing callback remote_entity_shadowing_schema_property_verbatim_named() doesn't work for Field API fields
Version: 7.x-1.0-beta6 » 7.x-1.x-dev
Category: Support request » Bug report
Status: Needs work » Fixed

Good catch!

(Ignore the test result; d.org testbot doesn't seem to like this module, I've just run the tests locally and they all pass.)

Committed. Thanks!

  • joachim committed 6e2aaac on 7.x-1.x authored by jonathan_hunt
    Issue #2407677 by jonathan_hunt: Fixed shadowing callback doesn't work...

Status: Fixed » Closed (fixed)

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