function ctools_entity_from_schema_get_children

1 call to ctools_entity_from_schema_get_children()
ctools_entity_from_schema_get_child in plugins/relationships/entity_from_schema.inc
1 string reference to 'ctools_entity_from_schema_get_children'
entity_from_schema.inc in plugins/relationships/entity_from_schema.inc
Plugin to provide an relationship handler for an entity from a field.

File

plugins/relationships/entity_from_schema.inc, line 25

Code

function ctools_entity_from_schema_get_children($parent_plugin, $parent) {
    $entities = entity_get_info();
    $plugins = array();
    foreach (module_implements('entity_info') as $module) {
        module_load_install($module);
        $schemas = drupal_get_schema();
        foreach ($entities as $from_entity => $from_entity_info) {
            if (empty($from_entity_info['base table'])) {
                continue;
            }
            $table = $from_entity_info['base table'];
            if (isset($schemas[$table]['foreign keys'])) {
                foreach ($schemas[$table]['foreign keys'] as $relationship => $info) {
                    foreach ($entities as $to_entity => $to_entity_info) {
                        if (empty($info['table'])) {
                            continue;
                        }
                        if (isset($to_entity_info['base table']) && $info['table'] == $to_entity_info['base table'] && in_array($to_entity_info['entity keys']['id'], $info['columns'])) {
                            $this_col = ctools_entity_from_schema_columns_filter($info['columns'], $to_entity_info['entity keys']['id']);
                            // Set up our t() replacements as we reuse these.
                            $replacements = array(
                                '@relationship' => $relationship,
                                '@base_table' => $table,
                                '@to_entity' => $to_entity_info['label'],
                                '@from_entity' => $from_entity_info['label'],
                            );
                            $name = $this_col . '-' . $from_entity . '-' . $to_entity;
                            $plugin_id = $parent . ':' . $name;
                            $plugin = $parent_plugin;
                            $plugin['title'] = t('@to_entity from @from_entity (on @base_table.@relationship)', $replacements);
                            $plugin['keyword'] = $to_entity;
                            $plugin['context name'] = $name;
                            $plugin['name'] = $plugin_id;
                            $plugin['description'] = t('Builds a relationship from a @from_entity to a @to_entity using the @base_table.@relationship field.', $replacements);
                            $plugin['required context'] = new ctools_context_required($from_entity_info['label'], $from_entity);
                            $plugin_entities = array(
                                'to' => $to_entity_info,
                                'from' => $from_entity_info,
                            );
                            $plugin_entities = array(
                                'to' => array(
                                    $to_entity => $to_entity_info,
                                ),
                                'from' => array(
                                    $from_entity => $from_entity_info,
                                ),
                            );
                            drupal_alter('ctools_entity_context', $plugin, $plugin_entities, $plugin_id);
                            $plugins[$plugin_id] = $plugin;
                            // Add the relation in the reverse direction.
                            $name = $this_col . '-' . $to_entity . '-' . $from_entity;
                            $plugin_id = $parent . ':' . $name;
                            $plugin = $parent_plugin;
                            $plugin['title'] = t('@from_entity from @to_entity (on @base_table.@relationship)', $replacements);
                            $plugin['keyword'] = $to_entity;
                            $plugin['context name'] = $name;
                            $plugin['name'] = $plugin_id;
                            $plugin['description'] = t('Builds a relationship from a @to_entity to a @from_entity using the @base_table.@relationship field.', $replacements);
                            $plugin['required context'] = new ctools_context_required($to_entity_info['label'], $to_entity);
                            $plugin_entities = array(
                                'to' => $from_entity_info,
                                'from' => $to_entity_info,
                            );
                            $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;
                        }
                    }
                }
            }
        }
    }
    drupal_alter('ctools_entity_contexts', $plugins);
    return $plugins;
}