Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There are some useful commits that can go in master along with a small bug fix. #7

Open
wants to merge 2 commits into
base: 7.x-1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 0 additions & 26 deletions createapi.api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion createapi.helpers.filters.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down
34 changes: 32 additions & 2 deletions createapi.helpers.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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) {
$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;

Expand Down Expand Up @@ -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;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion createapi.helpers.json.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 4 additions & 0 deletions createapi.info
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
name = CreateAPI
description = Create custom APIs
core = 7.x
version = "7.x-1.x-dev"
core = "7.x"
project = "createapi"
datestamp = "1382157116"