Problem/Motivation

Currently the ctools relationship plugin (field_collection_field_collection_from_field_get_children()) uses field_read_instances() to determine the child plugins.
Unfortunately this function doesn't have a cache and since we use it in a pretty simple way we could fetch the same data using field_info_instances() which uses a cache if possible.

Proposed resolution

Change the processing to be able to use field_info_instances().

This also adds bundle independent plugins as proposed here: #2348995: Provide bundle independent ctools relationship plugin

Remaining tasks

Reviews needed.

User interface changes

None.

API changes

I've seen that the bundle independent plugin definitions still use the context_name of the first bundle specific plugin. Because of the switch to field_info_instances() the processing order of bundles might changes, leading to a different context_name for bundle independent plugin definitions.
However, using the same context name for bundle specific and bundle independent plugin definitions seems odd anyway. So I guess if something should be fixed it's the generation of the context name of bundle independent plugin definitions and not the processing order.

Data model changes

None.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

das-peter created an issue. See original summary.

das-peter’s picture

Oh, looks like the bundle independent plugins base on another patch from me :D
#2348995: Provide bundle independent ctools relationship plugin
Will provide an adjustment for the context name here.

das-peter’s picture

Updated patch to set a dedicated context name for bundle independent plugin definitions.

chris matthews’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll, +Needs rework

The patch in #3 does not apply to the latest 7.x-1.x-dev and may be too old to reroll, but I went ahead and tagged the issue accordingly.

Checking patch ctools/relationships/field_collection_from_field.inc...
error: while searching for:
  if (isset($instances_info['field_collection_item'])) {
    $field_collection_items = $instances_info['field_collection_item'];

    foreach (field_read_instances() as $instance) {
      if (isset($field_collection_items[$instance['field_name']])) {
        $child_plugin_id = $parent . ':' . $instance['entity_type'] . ':' . $instance['bundle'] . ':' . $instance['field_name'];

        $child_plugin = $plugin;
        $child_plugin['context name'] = $instance['entity_type'] . ':' . $instance['bundle'] . ':' . $instance['field_name'];
        $child_plugin['title'] = t(
          '!label field collection (!field_name) from !entity_type (!bundle)',
          array(
          '!label' => $instance['label'],
          '!field_name' => $instance['field_name'],
          '!entity_type' => $instance['entity_type'],
          '!bundle' => $instance['bundle']
          )
        );
        $restrictions = array('type' => array($instance['bundle']));
        $child_plugin['required context'] = new ctools_context_required(ucfirst($instance['entity_type']), $instance['entity_type'], $restrictions);
        $child_plugin['parent'] = $parent;
        $child_plugin['keyword'] = 'Field collection';
        $child_plugin['entity_type'] = $instance['entity_type'];
        $child_plugin['field_name'] = $instance['field_name'];

        $child_plugin['name'] = $child_plugin_id;
        $plugins[$child_plugin_id] = $child_plugin;

      }
    }
  }

error: patch failed: ctools/relationships/field_collection_from_field.inc:34
error: ctools/relationships/field_collection_from_field.inc: patch does not apply

arti_parmar made their first commit to this issue’s fork.