From e335d195ba46967dcd8f0ffce1690d9194136631 Mon Sep 17 00:00:00 2001 From: Didarul Amin Date: Wed, 6 Aug 2014 12:08:41 -0400 Subject: [PATCH 1/2] Found some of your commits in msnbc repo which I think might be useful to be in the master --- createapi.api.php | 26 -------------------------- createapi.helpers.filters.inc | 2 +- createapi.helpers.inc | 34 ++++++++++++++++++++++++++++++++-- createapi.helpers.json.inc | 2 +- createapi.info | 7 +++++++ 5 files changed, 41 insertions(+), 30 deletions(-) diff --git a/createapi.api.php b/createapi.api.php index cbff5b3..e6cba93 100644 --- a/createapi.api.php +++ b/createapi.api.php @@ -237,29 +237,3 @@ function hook_createapi_variables() { ); } -/** - * Alter the output of an entity before it's added to a feed. - * - * CreateAPI automatically will prepare fields, properties, and path information - * based on hook_createapi_custom_entities_info() and other related hooks that - * define feed information. For properties that aren't supported by CreateAPI or - * for properties that need additional modification, this hook may be used - * to add or modify information on an individual item's output. - * - * @param array $item - * The associative array containing the item that will be JSON encoded. - * @param stdClass $entity - * The entity for the item being output. - * - * @see _createapi__helper__process_entities() - */ -function hook_createapi_process_entity_alter(&$item, $entity) { - if (isset($item['type']) && $item['type'] == 'photo') { - // Remove HTML tags for app delivery. - $item['description'] = strip_tags($item['description']); - - // Check if this entity is flagged. - $flag = flag_get_flag('promoted'); - $item['promoted'] = $flag->is_flagged($entity->nid); - } -} diff --git a/createapi.helpers.filters.inc b/createapi.helpers.filters.inc index 2d3cfd4..09baa93 100644 --- a/createapi.helpers.filters.inc +++ b/createapi.helpers.filters.inc @@ -47,7 +47,7 @@ function _createapi__helper__filter__field(EntityFieldQuery &$query, $param, $co $query_params = drupal_get_query_parameters(); $param_value = (isset($query_params[$param])) ? $query_params[$param] : FALSE; - if ($param_value) { + if ($param_value !== FALSE) { $param_value_split = explode(',', $param_value); $query->fieldCondition($field, $column, $param_value_split, 'IN'); } diff --git a/createapi.helpers.inc b/createapi.helpers.inc index 5c4d0ad..62e206f 100644 --- a/createapi.helpers.inc +++ b/createapi.helpers.inc @@ -52,8 +52,6 @@ function _createapi__helper__process_entities(array $eids, $entity_type, $fields } } - drupal_alter('createapi_process_entity', $field_output, $entity); - $output[] = $field_output; } @@ -140,10 +138,38 @@ function _createapi__helper__feed_format_field($entity_type, $entity, $field_nam $output[] = $reference; break; + case 'field_collection': + $entity_id = $items[$i]['value']; + $referenced_entity = entity_load('field_collection_item', array($entity_id)); + $reference = array(); + if ($referenced_entity[$entity_id]) { + $reference = array( + 'eid' => $entity_id , + ); + if (isset($current)) { + $referenced_entity = $referenced_entity[$entity_id]; + // Fields. + if (isset($current['fields'])) { + foreach ($current['fields'] as $key => $field) { + $reference[$key] = _createapi__helper__feed_format_field('field_collection_item', $referenced_entity, $field); + } + } + // Properties. + if (isset($current['properties'])) { + foreach ($current['properties'] as $key => $property) { + $reference[$key] = $referenced_entity->{$property}; + } + } + } + } + $output[] = $reference; + break; + case 'datetime': $output[] = strtotime($items[$i]['value']); break; case 'datestamp': + case 'time_of_day': $output[] = $items[$i]['value']; break; @@ -193,6 +219,10 @@ function _createapi__helper__feed_format_field($entity_type, $entity, $field_nam 'title' => (isset($items[$i]['title'])) ? $items[$i]['title'] : '', ); break; + case 'list_boolean': + case 'list_integer': + $output[] = (int) $items[$i]['value']; + break; } } } diff --git a/createapi.helpers.json.inc b/createapi.helpers.json.inc index 98dea5a..8676caf 100644 --- a/createapi.helpers.json.inc +++ b/createapi.helpers.json.inc @@ -21,7 +21,7 @@ function _createapi__helper__json_wrapper($rows, $wrapper_label, $row_label) { $output = array(); foreach ($rows as $row) { - $output[] = $row_label ? array($row_label => $row) : $row; + $output[] = array($row_label => $row); } $output = array($wrapper_label => $output); diff --git a/createapi.info b/createapi.info index 3c94cc2..19221ab 100644 --- a/createapi.info +++ b/createapi.info @@ -1,3 +1,10 @@ name = CreateAPI description = Create custom APIs core = 7.x + +; Information added by drupal.org packaging script on 2013-10-19 +version = "7.x-1.x-dev" +core = "7.x" +project = "createapi" +datestamp = "1382157116" + From 4b5711db90372f7fd4eb8d120748c93da22097ba Mon Sep 17 00:00:00 2001 From: Didarul Amin Date: Wed, 6 Aug 2014 12:10:35 -0400 Subject: [PATCH 2/2] Fixed bug that throws warning if array index not found. Remove Drupal.org created line --- createapi.helpers.inc | 2 +- createapi.info | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/createapi.helpers.inc b/createapi.helpers.inc index 62e206f..79931bf 100644 --- a/createapi.helpers.inc +++ b/createapi.helpers.inc @@ -142,7 +142,7 @@ function _createapi__helper__feed_format_field($entity_type, $entity, $field_nam $entity_id = $items[$i]['value']; $referenced_entity = entity_load('field_collection_item', array($entity_id)); $reference = array(); - if ($referenced_entity[$entity_id]) { + if ($referenced_entity) { $reference = array( 'eid' => $entity_id , ); diff --git a/createapi.info b/createapi.info index 19221ab..3c98706 100644 --- a/createapi.info +++ b/createapi.info @@ -1,10 +1,7 @@ name = CreateAPI description = Create custom APIs core = 7.x - -; Information added by drupal.org packaging script on 2013-10-19 version = "7.x-1.x-dev" core = "7.x" project = "createapi" datestamp = "1382157116" -