|
@@ -32,7 +32,7 @@ tripal_chado_set_globals();
|
|
|
* This function is used to set the global Chado variables
|
|
|
*
|
|
|
* @ingroup tripal_chado
|
|
|
-*/
|
|
|
+ */
|
|
|
function tripal_chado_set_globals() {
|
|
|
// these global variables are meant to be accessed by all Tripal
|
|
|
// modules to find the chado version installed and if Chado is local.
|
|
@@ -993,7 +993,7 @@ function tripal_chado_add_bundle_base_fields($entity_type_name, $bundle_name, $b
|
|
|
}
|
|
|
|
|
|
// If we don't have a field type then we don't need to create a field.
|
|
|
- if (!$field_info['field_type']) { http://www.phytozome.net/citrus.php
|
|
|
+ if (!$field_info['field_type']) {
|
|
|
// If we don't have a field type but it is required and doesn't have
|
|
|
// a default value then we are in trouble.
|
|
|
if ($field_info['is_required'] and !array_key_exists('default', $details)) {
|
|
@@ -1286,3 +1286,67 @@ function tripal_chado_describe_args($callback, $args) {
|
|
|
return $new_args;
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Implements hook_entity_property_info_alter().
|
|
|
+ *
|
|
|
+ * This is being implemented to ensure chado fields are exposed for search api indexing.
|
|
|
+ * All fields are available for index by default but the getter function set by default
|
|
|
+ * is not actually capable of getting the value from chado. Thus we change the getter
|
|
|
+ * function to one that can :-).
|
|
|
+ */
|
|
|
+function tripal_chado_entity_property_info_alter(&$info) {
|
|
|
+
|
|
|
+ // Get a list of fields with the chado storage backend.
|
|
|
+
|
|
|
+ // Loop through all of the bundles.
|
|
|
+ if (isset($info['TripalEntity']['bundles'])) {
|
|
|
+ foreach ($info['TripalEntity']['bundles'] as $bundle_id => $bundle) {
|
|
|
+ // Loop through each of the fields for a given bundle.
|
|
|
+ foreach ($bundle['properties'] as $field_name => $field_info) {
|
|
|
+ // If the field is a chado field, then change the callback.
|
|
|
+ // @todo check this properly.
|
|
|
+ if (preg_match('/(\w+)__(\w+)/', $field_name, $matches)) {
|
|
|
+ $info['TripalEntity']['bundles'][$bundle_id]['properties'][$field_name]['getter callback'] =
|
|
|
+ 'tripal_chado_entity_property_get_value';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Provides a way for the search api to grab the value of a chado field.
|
|
|
+ *
|
|
|
+ * @param $entity
|
|
|
+ * The fully-loaded entity object to be indexed.
|
|
|
+ * @param $options
|
|
|
+ * Options that can be ued when retrieving the value.
|
|
|
+ * @param $field_name
|
|
|
+ * The machine name of the field we want to retrieve.
|
|
|
+ * @param $entity_type
|
|
|
+ * The type of entity (ie: TripalEntity).
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ * The rendered value of the field specified by $field_name.
|
|
|
+ */
|
|
|
+function tripal_chado_entity_property_get_value($entity, $options, $field_name, $entity_type) {
|
|
|
+
|
|
|
+ $display = array(
|
|
|
+ 'type' => '',
|
|
|
+ 'label' => 'hidden',
|
|
|
+ );
|
|
|
+
|
|
|
+ $langcode = LANGUAGE_NONE;
|
|
|
+ $items = field_get_items($entity_type, $entity, $field_name);
|
|
|
+ if (count($items) == 1) {
|
|
|
+ $render_array = field_view_value($entity_type, $entity, $field_name, $items[0], $display, $langcode);
|
|
|
+ }
|
|
|
+ // @todo: handle fields with multiple values.
|
|
|
+ else {
|
|
|
+ $render_array = field_view_value($entity_type, $entity, $field_name, $items[0], $display, $langcode);
|
|
|
+ drupal_set_message('Tripal Chado currently only supports views integration for single value fields. The first value has been shown.', 'warning');
|
|
|
+ }
|
|
|
+
|
|
|
+ return drupal_render($render_array);
|
|
|
+}
|