The new ability to export objects from joined tables is awesome! But it would be even more awesome if we could support exporting objects which joins a one-to-many relationship table.

I found that it's not that hard to do this. The only API addition we need is that each join that is a one-to-many relationship needs to define array_key like this:

  'join' => array(
    'term' => array(
      'table' => 'ctools_plugin_example_object_term',
      'left_key' => 'oid',
      'right_key' => 'oid',
      // One-to-many relationships must define 'array_key'. Can be either
      // EXPORT_NUMERIC_ARRAY or a field name from the joined table.
      'array_key' => EXPORT_NUMERIC_ARRAY,
      'load' => array(
        'name',
        'synonym',
      ),
    ),
  ),

The export should then look something like this:

  $object = new stdClass;
  $object->disabled = FALSE; /* Edit this to true to make a default object disabled initially */
  $object->api_version = 1;
  $object->machine_name = 'example';
  $object->title = 'Example';
  $object->body = 'Hello world';
    $term = new stdClass;
    $term->name = 'Lorem';
    $term->synonym = '';
  $object->term[] = $term;
    $term = new stdClass;
    $term->name = 'Ipsum';
    $term->synonym = '';
  $object->term[] = $term;

The join key is used as the identifier for child objects ($term).

Attached is two patches. One with only the API addition and one that adds an example module implementing this and an export_ui plugin. The example module is working, but not at all complete. Just so you can take a look at it.

Comments

dixon_’s picture

Component: Code » Exportables

Ping.

Bastlynn’s picture

Any chance of this getting added?

Bastlynn’s picture

japerry’s picture

Status: Needs review » Closed (outdated)

Drupal 7 is no longer supported, closing.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.