diff --git a/plugins/relationships/entity_from_field.inc b/plugins/relationships/entity_from_field.inc index d4880c6..2849154 100644 --- a/plugins/relationships/entity_from_field.inc +++ b/plugins/relationships/entity_from_field.inc @@ -21,6 +21,7 @@ $plugin = array( function ctools_entity_from_field_get_child($plugin, $parent, $child) { $plugins = ctools_entity_from_field_get_children($plugin, $parent); + return $plugins[$parent . ':' . $child]; } @@ -86,39 +87,81 @@ function ctools_entity_from_field_get_children($parent_plugin, $parent) { $plugin['source key'] = current(array_keys($info['columns'])); $plugin['parent'] = $parent; + if (count($info['columns']) > 1) { + $plugin['title'] .= ' ' . t('[DEPRECATED]'); + $plugin['description'] .= ' ' . t('This relationship should be substituted for one of the derivative relationships.'); + } + $plugins[$plugin_id] = $plugin; -/* --- commented out until I figure out how to actually load the reverse properly. - // Build the reverse - $plugin = $parent_plugin; - $name = $field_name . '-' . $from_entity . '-' . $to_entity . '-reverse'; - $plugin_id = $parent . ':' . $name; + /* + -- commented out until I figure out how to actually load the reverse properly. + // Build the reverse + $plugin = $parent_plugin; + $name = $field_name . '-' . $from_entity . '-' . $to_entity . '-reverse'; + $plugin_id = $parent . ':' . $name; - $plugin['title'] = t('@from_entity from @to_entity (on @from_entity: @field_name)', $replacements); - $plugin['keyword'] = $to_entity; - $plugin['context name'] = $name; - $plugin['name'] = $plugin_id; - $plugin['description'] = t('Creates a @from_entity context from @to_entity using the @field_name field on @from_entity.', $replacements); + $plugin['title'] = t('@from_entity from @to_entity (on @from_entity: @field_name)', $replacements); + $plugin['keyword'] = $to_entity; + $plugin['context name'] = $name; + $plugin['name'] = $plugin_id; + $plugin['description'] = t('Creates a @from_entity context from @to_entity using the @field_name field on @from_entity.', $replacements); - $plugin['from entity'] = $from_entity; - $plugin['to entity'] = $to_entity; - $plugin['field name'] = $field_name; - $plugin['reverse'] = TRUE; - $plugin['parent'] = $parent; + $plugin['from entity'] = $from_entity; + $plugin['to entity'] = $to_entity; + $plugin['field name'] = $field_name; + $plugin['reverse'] = TRUE; + $plugin['parent'] = $parent; - // Since we can't apply restrictions on the reverse relationship - // we just add the required context here. - $plugin['required context'] = new ctools_context_required($to_entity_info['label'], $to_entity); + // Since we can't apply restrictions on the reverse relationship + // we just add the required context here. + $plugin['required context'] = new ctools_context_required($to_entity_info['label'], $to_entity); - $plugin_entities = array( - 'to' => array($from_entity => $from_entity_info), - 'from' => array($to_entity => $to_entity_info) - ); - drupal_alter('ctools_entity_context', $plugin, $plugin_entities, $plugin_id); + $plugin_entities = array( + 'to' => array($from_entity => $from_entity_info), + 'from' => array($to_entity => $to_entity_info) + ); + drupal_alter('ctools_entity_context', $plugin, $plugin_entities, $plugin_id); + + $plugins[$plugin_id] = $plugin; + */ - $plugins[$plugin_id] = $plugin; -*/ + } + + if (count($info['columns']) > 1) { + foreach ($info['columns'] as $column => $column_key) { + $name = $field_name . '|' . $column . '-' . $from_entity . '-' . $to_entity; + $plugin_id = $parent . ':' . $name; + + // Record the bundle for later. + $context_types[$plugin_id]['types'][$bundle] = $from_entity_info['bundles'][$bundle]['label']; + + // We check for every bundle; this plugin may already have + // been created, so don't recreate it. + if (!isset($plugins[$plugin_id])) { + $plugin = $parent_plugin; + $replacements = array( + '@to_entity' => $to_entity_info['label'], + '@from_entity' => $from_entity_info['label'], + '@field_name' => $field_name, + '@key' => $column, + '@field_label' => ctools_field_label($field_name), + ); + $plugin['title'] = t('@to_entity from @from_entity (on @from_entity: @field_label [@field_name:@key])', $replacements); + $plugin['keyword'] = $to_entity . '_' . $column; + $plugin['context name'] = $name; + $plugin['name'] = $plugin_id; + $plugin['description'] = t('Creates a @to_entity context from @from_entity using the @field_name:@key field on @from_entity.', $replacements); + $plugin['from entity'] = $from_entity; + $plugin['to entity'] = $to_entity; + $plugin['field name'] = $field_name; + $plugin['join key'] = $key; + $plugin['source key'] = $column; + $plugin['parent'] = $parent; + + $plugins[$plugin_id] = $plugin; + } + } } } } @@ -131,7 +174,13 @@ function ctools_entity_from_field_get_children($parent_plugin, $parent) { foreach ($context_types as $key => $context) { list($parent, $plugin_name) = explode(':', $key); - list($field_name, $from_entity, $to_entity) = explode('-', $plugin_name); + list($field_name_key, $from_entity, $to_entity) = explode('-', $plugin_name); + if (strstr($field_name_key, '|')) { + list($field_name, $column_key) = explode('|', $field_name_key); + } + else { + $field_name = $field_name_key; + } $from_entity_info = $entities[$from_entity]; $to_entity_info = $entities[$to_entity]; @@ -147,6 +196,7 @@ function ctools_entity_from_field_get_children($parent_plugin, $parent) { drupal_alter('ctools_entity_contexts', $plugins); $cache[$cid] = $plugins; + return $plugins; } @@ -162,7 +212,14 @@ function ctools_entity_from_field_context($context, $conf) { $delta = !empty($conf['delta']) ? intval($conf['delta']) : 0; $plugin = $conf['name']; list($plugin, $plugin_name) = explode(':', $plugin); - list($field_name, $from_entity, $to_entity) = explode('-', $plugin_name); + list($field_name_key, $from_entity, $to_entity) = explode('-', $plugin_name); + if (strstr($field_name_key, '|')) { + list($field_name, $column_key) = explode('|', $field_name_key); + } + else { + $field_name = $field_name_key; + } + // If unset it wants a generic, unfilled context, which is just NULL. $entity_info = entity_get_info($from_entity); if (empty($context->data) || !isset($context->data->{$entity_info['entity keys']['id']})) {