I am trying to use search API with the REST API provided with services. I have a view(as described below), a search index which indexes nodes, and a service endpoint. When i use the browser to directly access the view, the results are correct, but when I send a get request to the rest endpoint, I get something like

[
{
"price": null,
"description": null,
"title": "",
"image_url": "",
"company": "",
"hot_deal": null,
"nid": "0",
"name": "",
"uid": "0",
"html": null
}
]

The view:

$view = new view();
$view->name = 'search_products';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'search_api_index_products';
$view->human_name = 'Search Products';
$view->core = 7;
$view->pi_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'none';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'fields';
/* No results behavior: Global: Result summary */
$handler->display->display_options['empty']['result']['id'] = 'result';
$handler->display->display_options['empty']['result']['table'] = 'views';
$handler->display->display_options['empty']['result']['field'] = 'result';
$handler->display->display_options['empty']['result']['empty'] = TRUE;
/* Relationship: Indexed Node: Author */
$handler->display->display_options['relationships']['author']['id'] = 'author';
$handler->display->display_options['relationships']['author']['table'] = 'search_api_index_products';
$handler->display->display_options['relationships']['author']['field'] = 'author';
/* Relationship: Indexed Node: Image » The image file. */
$handler->display->display_options['relationships']['field_image_file']['id'] = 'field_image_file';
$handler->display->display_options['relationships']['field_image_file']['table'] = 'search_api_index_products';
$handler->display->display_options['relationships']['field_image_file']['field'] = 'field_image_file';
/* Relationship: User: Exhibitor profile */
$handler->display->display_options['relationships']['profile_exhibitor']['id'] = 'profile_exhibitor';
$handler->display->display_options['relationships']['profile_exhibitor']['table'] = 'entity_user';
$handler->display->display_options['relationships']['profile_exhibitor']['field'] = 'profile_exhibitor';
$handler->display->display_options['relationships']['profile_exhibitor']['relationship'] = 'author';
/* Field: Indexed Node: Price */
$handler->display->display_options['fields']['field_price']['id'] = 'field_price';
$handler->display->display_options['fields']['field_price']['table'] = 'search_api_index_products';
$handler->display->display_options['fields']['field_price']['field'] = 'field_price';
$handler->display->display_options['fields']['field_price']['label'] = 'price';
$handler->display->display_options['fields']['field_price']['settings'] = array(
  'thousand_separator' => '',
  'prefix_suffix' => 1,
);
/* Field: Indexed Node: The main body text */
$handler->display->display_options['fields']['body']['id'] = 'body';
$handler->display->display_options['fields']['body']['table'] = 'search_api_index_products';
$handler->display->display_options['fields']['body']['field'] = 'body';
$handler->display->display_options['fields']['body']['label'] = 'description';
$handler->display->display_options['fields']['body']['type'] = 'text_plain';
/* Field: Indexed Node: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'search_api_index_products';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['label'] = 'title';
$handler->display->display_options['fields']['title']['link_to_entity'] = 0;
/* Field: File: URL */
$handler->display->display_options['fields']['url']['id'] = 'url';
$handler->display->display_options['fields']['url']['table'] = 'entity_file';
$handler->display->display_options['fields']['url']['field'] = 'url';
$handler->display->display_options['fields']['url']['relationship'] = 'field_image_file';
$handler->display->display_options['fields']['url']['label'] = 'image_url';
$handler->display->display_options['fields']['url']['link_to_entity'] = 0;
/* Field: Profile: Company » Company */
$handler->display->display_options['fields']['field_profile_organisation_name']['id'] = 'field_profile_organisation_name';
$handler->display->display_options['fields']['field_profile_organisation_name']['table'] = 'entity_profile2';
$handler->display->display_options['fields']['field_profile_organisation_name']['field'] = 'field_profile_organisation_name';
$handler->display->display_options['fields']['field_profile_organisation_name']['relationship'] = 'profile_exhibitor';
$handler->display->display_options['fields']['field_profile_organisation_name']['label'] = 'company';
$handler->display->display_options['fields']['field_profile_organisation_name']['link_to_entity'] = 0;
/* Field: Indexed Node: Hot Deal */
$handler->display->display_options['fields']['field_hot_deal']['id'] = 'field_hot_deal';
$handler->display->display_options['fields']['field_hot_deal']['table'] = 'search_api_index_products';
$handler->display->display_options['fields']['field_hot_deal']['field'] = 'field_hot_deal';
$handler->display->display_options['fields']['field_hot_deal']['label'] = 'hot_deal';
/* Field: Indexed Node: Node ID */
$handler->display->display_options['fields']['nid_1']['id'] = 'nid_1';
$handler->display->display_options['fields']['nid_1']['table'] = 'search_api_index_products';
$handler->display->display_options['fields']['nid_1']['field'] = 'nid';
$handler->display->display_options['fields']['nid_1']['label'] = 'nid';
$handler->display->display_options['fields']['nid_1']['separator'] = '';
$handler->display->display_options['fields']['nid_1']['link_to_entity'] = 0;
/* Field: User: Name */
$handler->display->display_options['fields']['name']['id'] = 'name';
$handler->display->display_options['fields']['name']['table'] = 'entity_user';
$handler->display->display_options['fields']['name']['field'] = 'name';
$handler->display->display_options['fields']['name']['relationship'] = 'author';
/* Field: User: User ID */
$handler->display->display_options['fields']['uid']['id'] = 'uid';
$handler->display->display_options['fields']['uid']['table'] = 'entity_user';
$handler->display->display_options['fields']['uid']['field'] = 'uid';
$handler->display->display_options['fields']['uid']['relationship'] = 'author';
$handler->display->display_options['fields']['uid']['label'] = 'uid';
$handler->display->display_options['fields']['uid']['separator'] = '';
$handler->display->display_options['fields']['uid']['link_to_entity'] = 0;
/* Field: Indexed Node: The main body text */
$handler->display->display_options['fields']['body_1']['id'] = 'body_1';
$handler->display->display_options['fields']['body_1']['table'] = 'search_api_index_products';
$handler->display->display_options['fields']['body_1']['field'] = 'body';
$handler->display->display_options['fields']['body_1']['label'] = 'html';
$handler->display->display_options['filter_groups']['groups'] = array(
  1 => 'AND',
  2 => 'AND',
);
/* Filter criterion: Indexed Node: Price */
$handler->display->display_options['filters']['field_price']['id'] = 'field_price';
$handler->display->display_options['filters']['field_price']['table'] = 'search_api_index_products';
$handler->display->display_options['filters']['field_price']['field'] = 'field_price';
$handler->display->display_options['filters']['field_price']['operator'] = '>=';
$handler->display->display_options['filters']['field_price']['group'] = 1;
$handler->display->display_options['filters']['field_price']['exposed'] = TRUE;
$handler->display->display_options['filters']['field_price']['expose']['operator_id'] = 'field_price_op';
$handler->display->display_options['filters']['field_price']['expose']['label'] = 'price_smaller';
$handler->display->display_options['filters']['field_price']['expose']['operator'] = 'field_price_op';
$handler->display->display_options['filters']['field_price']['expose']['identifier'] = 'field_price';
$handler->display->display_options['filters']['field_price']['expose']['remember_roles'] = array(
  2 => '2',
  1 => 0,
  3 => 0,
  6 => 0,
  4 => 0,
  7 => 0,
  5 => 0,
  8 => 0,
);
$handler->display->display_options['filters']['field_price']['group_info']['label'] = 'Price';
$handler->display->display_options['filters']['field_price']['group_info']['identifier'] = 'field_price';
$handler->display->display_options['filters']['field_price']['group_info']['remember'] = FALSE;
$handler->display->display_options['filters']['field_price']['group_info']['group_items'] = array(
  1 => array(),
  2 => array(),
  3 => array(),
);
/* Filter criterion: Indexed Node: Price */
$handler->display->display_options['filters']['field_price_1']['id'] = 'field_price_1';
$handler->display->display_options['filters']['field_price_1']['table'] = 'search_api_index_products';
$handler->display->display_options['filters']['field_price_1']['field'] = 'field_price';
$handler->display->display_options['filters']['field_price_1']['operator'] = '<=';
$handler->display->display_options['filters']['field_price_1']['group'] = 1;
$handler->display->display_options['filters']['field_price_1']['exposed'] = TRUE;
$handler->display->display_options['filters']['field_price_1']['expose']['operator_id'] = 'field_price_1_op';
$handler->display->display_options['filters']['field_price_1']['expose']['label'] = 'price_larger';
$handler->display->display_options['filters']['field_price_1']['expose']['operator'] = 'field_price_1_op';
$handler->display->display_options['filters']['field_price_1']['expose']['identifier'] = 'field_price_1';
$handler->display->display_options['filters']['field_price_1']['expose']['remember_roles'] = array(
  2 => '2',
  1 => 0,
  3 => 0,
  6 => 0,
  4 => 0,
  7 => 0,
  5 => 0,
  8 => 0,
);
/* Filter criterion: Indexed Node: Title */
$handler->display->display_options['filters']['title']['id'] = 'title';
$handler->display->display_options['filters']['title']['table'] = 'search_api_index_products';
$handler->display->display_options['filters']['title']['field'] = 'title';
$handler->display->display_options['filters']['title']['group'] = 2;
$handler->display->display_options['filters']['title']['exposed'] = TRUE;
$handler->display->display_options['filters']['title']['expose']['operator_id'] = 'title_op';
$handler->display->display_options['filters']['title']['expose']['label'] = 'name';
$handler->display->display_options['filters']['title']['expose']['operator'] = 'title_op';
$handler->display->display_options['filters']['title']['expose']['identifier'] = 'title';
$handler->display->display_options['filters']['title']['expose']['remember_roles'] = array(
  2 => '2',
  1 => 0,
  3 => 0,
  6 => 0,
  4 => 0,
  7 => 0,
  5 => 0,
  8 => 0,
);

/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page_1');
$handler->display->display_options['defaults']['hide_admin_links'] = FALSE;
$handler->display->display_options['path'] = 'psearch';
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Dippers’s picture

This fails because search_api views uses entity views. However the simple rendering employed by Services Views doesn't render entity views fields. In particular entity view fields need to be pre_rendered before they are displayed as it is the pre_render that wrappers the entity and attaches it to the view.

I have attached a patch for this but I haven't tried it out on all possible use cases. It works fine for entity views but it might break standard views. The patch also normalises the differences between rendering in views preview and in service output as I preferred them to be exactly the same.

Dippers’s picture

This is a slightly more aggressive patch in that it themes every field even if the raw data is available in the results. This ensures any rewrite/link post processing is also done on all fields.

frankyn’s picture

Hi,

Awesome work on the patch you made. I applied it and got a few funny results. I'm attaching the before/after json structures that are being printed out.

array (
0 => 
stdClass::__set_state(array(
'users_message_name' => 'admin',
'users_message_created' => '1361864700',
'message_users_mid' => '1',
'message_users_uid' => '1',
)),
1 => 
stdClass::__set_state(array(
'users_message_name' => 'admin',
'users_message_created' => '1361864700',
'message_users_mid' => '2',
'message_users_uid' => '1',
)),
2 => 
stdClass::__set_state(array(
'users_message_name' => 'admin',
'users_message_created' => '1361864700',
'message_users_mid' => '1',
'message_users_uid' => '1',
)),
3 => 
stdClass::__set_state(array(
'users_message_name' => 'admin',
'users_message_created' => '1361864700',
'message_users_mid' => '2',
'message_users_uid' => '1',
)),
)
array (
0 => 
stdClass::__set_state(array(
'users_message_name' => 'admin',
'users_message_created' => 'Tuesday, February 26, 2013 - 01:45',
'message_users_mid' => 'TEST',
'message_users_uid' => '1',
'unknown' => '1111TEST',
)),
1 => 
stdClass::__set_state(array(
'users_message_name' => 'admin',
'users_message_created' => 'Tuesday, February 26, 2013 - 01:45',
'message_users_mid' => 'testsetsdfs',
'message_users_uid' => '2',
'unknown' => '2222testsetsdfs',
)),
2 => 
stdClass::__set_state(array(
'users_message_name' => 'admin',
'users_message_created' => 'Tuesday, February 26, 2013 - 01:45',
'message_users_mid' => 'TEST',
'message_users_uid' => '1',
'unknown' => '1111TEST',
)),
3 => 
stdClass::__set_state(array(
'users_message_name' => 'admin',
'users_message_created' => 'Tuesday, February 26, 2013 - 01:45',
'message_users_mid' => 'testsetsdfs',
'message_users_uid' => '2',
'unknown' => '2222testsetsdfs',
)),

If there is anything I can do to help, please let me know.
Again awesome work and thanks a lot!
Frank N.

Dippers’s picture

What is the expected output? I would need to see the exported view to see what rewrite rules you have in place. Which endpoint are you using, direct from the views service or from the generic /views/{view_id}?display_id={display_id} ?

matthand’s picture

I'm working with Frankyn and he's using a custom path in services views that is used as a new service resource. He's not calling the endpoint with the views resource. It's more like {domain}/{rest_server}/notifications.json

And the main issue we see is that a Global Custom Text field with a token rewrite is working great. BUT, the value is somehow included as the Message ID as well. You can see it in his printout. The message_users_mid field should equal an integer (1, 2, 3, etc) but it's instead equaling a token form the Global Custom Text field below it called "unknown". And, the label doesn't show as the field name for the custom text field. It always shows as "unknown" despite what is entered as a label.

Thank you for the patch. It's a huge improvement over the original formatting of Services Views. Frankyn will be available late today and he'll provide a views export for you to look at. He's also here to help code and squash bugs if you need it.

frankyn’s picture

I added an export for the view definitions below:

$view = new view();
$view->name = 'scribble';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'message';
$view->human_name = 'scribble';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'scribble';
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'none';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['items_per_page'] = '10';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'fields';
/* Relationship: Message: User uid */
$handler->display->display_options['relationships']['user']['id'] = 'user';
$handler->display->display_options['relationships']['user']['table'] = 'message';
$handler->display->display_options['relationships']['user']['field'] = 'user';
/* Relationship: User: Message */
$handler->display->display_options['relationships']['message']['id'] = 'message';
$handler->display->display_options['relationships']['message']['table'] = 'users';
$handler->display->display_options['relationships']['message']['field'] = 'message';
$handler->display->display_options['relationships']['message']['relationship'] = 'user';
/* Field: User: Name */
$handler->display->display_options['fields']['name']['id'] = 'name';
$handler->display->display_options['fields']['name']['table'] = 'users';
$handler->display->display_options['fields']['name']['field'] = 'name';
$handler->display->display_options['fields']['name']['relationship'] = 'user';
/* Field: User: Created date */
$handler->display->display_options['fields']['created']['id'] = 'created';
$handler->display->display_options['fields']['created']['table'] = 'users';
$handler->display->display_options['fields']['created']['field'] = 'created';
$handler->display->display_options['fields']['created']['relationship'] = 'user';
$handler->display->display_options['fields']['created']['date_format'] = 'long';
/* Field: Message: Content */
$handler->display->display_options['fields']['field_content']['id'] = 'field_content';
$handler->display->display_options['fields']['field_content']['table'] = 'field_data_field_content';
$handler->display->display_options['fields']['field_content']['field'] = 'field_content';
$handler->display->display_options['fields']['field_content']['relationship'] = 'message';
$handler->display->display_options['fields']['field_content']['settings'] = array(
  'link' => 1,
);
/* Field: Message: Rendered Message */
$handler->display->display_options['fields']['rendered_entity']['id'] = 'rendered_entity';
$handler->display->display_options['fields']['rendered_entity']['table'] = 'views_entity_message';
$handler->display->display_options['fields']['rendered_entity']['field'] = 'rendered_entity';
$handler->display->display_options['fields']['rendered_entity']['relationship'] = 'message';
$handler->display->display_options['fields']['rendered_entity']['link_to_entity'] = 1;
$handler->display->display_options['fields']['rendered_entity']['view_mode'] = 'full';
/* Field: Global: Custom text */
$handler->display->display_options['fields']['nothing']['id'] = 'nothing';
$handler->display->display_options['fields']['nothing']['table'] = 'views';
$handler->display->display_options['fields']['nothing']['field'] = 'nothing';
$handler->display->display_options['fields']['nothing']['alter']['text'] = '[rendered_entity][rendered_entity][rendered_entity][rendered_entity][field_content]';

/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page');
$handler->display->display_options['defaults']['hide_admin_links'] = FALSE;
$handler->display->display_options['path'] = 'scribble';

/* Display: Services */
$handler = $view->new_display('services', 'Services', 'services_1');
$handler->display->display_options['defaults']['hide_admin_links'] = FALSE;
$handler->display->display_options['path'] = 'scribbles';

Dippers’s picture

Your view is working as expected.

Labels for service view fields must only include lower case and underscores. Change your global text field label to 'custom' and it will work whereas 'Custom Text' which is the default will not.

Your view doesn't actually have the message id field included. The message id label is actually on the content field. If you change your labels to actually indicate the field they are on you will see what I mean. I'm not sure what the rendered message field should be giving.

Here is the view with labels set and the message id field added:

$view = new view;
$view->name = 'scribble';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'message';
$view->human_name = 'scribble';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'scribble';
$handler->display->display_options['access']['type'] = 'none';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['query']['options']['query_comment'] = FALSE;
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['items_per_page'] = '10';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'fields';
/* Relationship: Message: User uid */
$handler->display->display_options['relationships']['user']['id'] = 'user';
$handler->display->display_options['relationships']['user']['table'] = 'message';
$handler->display->display_options['relationships']['user']['field'] = 'user';
/* Relationship: User: Message */
$handler->display->display_options['relationships']['message']['id'] = 'message';
$handler->display->display_options['relationships']['message']['table'] = 'users';
$handler->display->display_options['relationships']['message']['field'] = 'message';
$handler->display->display_options['relationships']['message']['relationship'] = 'user';
/* Field: User: Name */
$handler->display->display_options['fields']['name']['id'] = 'name';
$handler->display->display_options['fields']['name']['table'] = 'users';
$handler->display->display_options['fields']['name']['field'] = 'name';
$handler->display->display_options['fields']['name']['relationship'] = 'user';
$handler->display->display_options['fields']['name']['label'] = 'name';
$handler->display->display_options['fields']['name']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['name']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['name']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['name']['alter']['external'] = 0;
$handler->display->display_options['fields']['name']['alter']['replace_spaces'] = 0;
$handler->display->display_options['fields']['name']['alter']['trim_whitespace'] = 0;
$handler->display->display_options['fields']['name']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['name']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['name']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['name']['alter']['more_link'] = 0;
$handler->display->display_options['fields']['name']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['name']['alter']['trim'] = 0;
$handler->display->display_options['fields']['name']['alter']['html'] = 0;
$handler->display->display_options['fields']['name']['element_label_colon'] = 0;
$handler->display->display_options['fields']['name']['element_default_classes'] = 1;
$handler->display->display_options['fields']['name']['hide_empty'] = 0;
$handler->display->display_options['fields']['name']['empty_zero'] = 0;
$handler->display->display_options['fields']['name']['hide_alter_empty'] = 1;
$handler->display->display_options['fields']['name']['link_to_user'] = 0;
$handler->display->display_options['fields']['name']['overwrite_anonymous'] = 0;
$handler->display->display_options['fields']['name']['format_username'] = 1;
/* Field: User: Created date */
$handler->display->display_options['fields']['created']['id'] = 'created';
$handler->display->display_options['fields']['created']['table'] = 'users';
$handler->display->display_options['fields']['created']['field'] = 'created';
$handler->display->display_options['fields']['created']['relationship'] = 'user';
$handler->display->display_options['fields']['created']['label'] = 'created';
$handler->display->display_options['fields']['created']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['created']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['created']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['created']['alter']['external'] = 0;
$handler->display->display_options['fields']['created']['alter']['replace_spaces'] = 0;
$handler->display->display_options['fields']['created']['alter']['trim_whitespace'] = 0;
$handler->display->display_options['fields']['created']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['created']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['created']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['created']['alter']['more_link'] = 0;
$handler->display->display_options['fields']['created']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['created']['alter']['trim'] = 0;
$handler->display->display_options['fields']['created']['alter']['html'] = 0;
$handler->display->display_options['fields']['created']['element_label_colon'] = 0;
$handler->display->display_options['fields']['created']['element_default_classes'] = 1;
$handler->display->display_options['fields']['created']['hide_empty'] = 0;
$handler->display->display_options['fields']['created']['empty_zero'] = 0;
$handler->display->display_options['fields']['created']['hide_alter_empty'] = 1;
$handler->display->display_options['fields']['created']['date_format'] = 'long';
/* Field: Message: Content */
$handler->display->display_options['fields']['field_content']['id'] = 'field_content';
$handler->display->display_options['fields']['field_content']['table'] = 'field_data_field_content';
$handler->display->display_options['fields']['field_content']['field'] = 'field_content';
$handler->display->display_options['fields']['field_content']['relationship'] = 'message';
$handler->display->display_options['fields']['field_content']['label'] = 'content';
$handler->display->display_options['fields']['field_content']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['field_content']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['field_content']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['field_content']['alter']['external'] = 0;
$handler->display->display_options['fields']['field_content']['alter']['replace_spaces'] = 0;
$handler->display->display_options['fields']['field_content']['alter']['trim_whitespace'] = 0;
$handler->display->display_options['fields']['field_content']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['field_content']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['field_content']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['field_content']['alter']['more_link'] = 0;
$handler->display->display_options['fields']['field_content']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['field_content']['alter']['trim'] = 0;
$handler->display->display_options['fields']['field_content']['alter']['html'] = 0;
$handler->display->display_options['fields']['field_content']['element_label_colon'] = 0;
$handler->display->display_options['fields']['field_content']['element_default_classes'] = 1;
$handler->display->display_options['fields']['field_content']['hide_empty'] = 0;
$handler->display->display_options['fields']['field_content']['empty_zero'] = 0;
$handler->display->display_options['fields']['field_content']['hide_alter_empty'] = 1;
$handler->display->display_options['fields']['field_content']['settings'] = array(
  'link' => 1,
);
$handler->display->display_options['fields']['field_content']['field_api_classes'] = 0;
/* Field: Message: Rendered Message */
$handler->display->display_options['fields']['rendered_entity']['id'] = 'rendered_entity';
$handler->display->display_options['fields']['rendered_entity']['table'] = 'views_entity_message';
$handler->display->display_options['fields']['rendered_entity']['field'] = 'rendered_entity';
$handler->display->display_options['fields']['rendered_entity']['relationship'] = 'message';
$handler->display->display_options['fields']['rendered_entity']['label'] = 'rendered';
$handler->display->display_options['fields']['rendered_entity']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['rendered_entity']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['rendered_entity']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['rendered_entity']['alter']['external'] = 0;
$handler->display->display_options['fields']['rendered_entity']['alter']['replace_spaces'] = 0;
$handler->display->display_options['fields']['rendered_entity']['alter']['trim_whitespace'] = 0;
$handler->display->display_options['fields']['rendered_entity']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['rendered_entity']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['rendered_entity']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['rendered_entity']['alter']['more_link'] = 0;
$handler->display->display_options['fields']['rendered_entity']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['rendered_entity']['alter']['trim'] = 0;
$handler->display->display_options['fields']['rendered_entity']['alter']['html'] = 0;
$handler->display->display_options['fields']['rendered_entity']['element_label_colon'] = 0;
$handler->display->display_options['fields']['rendered_entity']['element_default_classes'] = 1;
$handler->display->display_options['fields']['rendered_entity']['hide_empty'] = 0;
$handler->display->display_options['fields']['rendered_entity']['empty_zero'] = 0;
$handler->display->display_options['fields']['rendered_entity']['hide_alter_empty'] = 1;
$handler->display->display_options['fields']['rendered_entity']['link_to_entity'] = 0;
$handler->display->display_options['fields']['rendered_entity']['view_mode'] = 'full';
/* Field: Global: Custom text */
$handler->display->display_options['fields']['nothing']['id'] = 'nothing';
$handler->display->display_options['fields']['nothing']['table'] = 'views';
$handler->display->display_options['fields']['nothing']['field'] = 'nothing';
$handler->display->display_options['fields']['nothing']['label'] = 'hello_world';
$handler->display->display_options['fields']['nothing']['alter']['text'] = '[rendered_entity][rendered_entity][rendered_entity][rendered_entity][field_content]';
$handler->display->display_options['fields']['nothing']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['nothing']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['nothing']['alter']['external'] = 0;
$handler->display->display_options['fields']['nothing']['alter']['replace_spaces'] = 0;
$handler->display->display_options['fields']['nothing']['alter']['trim_whitespace'] = 0;
$handler->display->display_options['fields']['nothing']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['nothing']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['nothing']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['nothing']['alter']['more_link'] = 0;
$handler->display->display_options['fields']['nothing']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['nothing']['alter']['trim'] = 0;
$handler->display->display_options['fields']['nothing']['alter']['html'] = 0;
$handler->display->display_options['fields']['nothing']['element_label_colon'] = 0;
$handler->display->display_options['fields']['nothing']['element_default_classes'] = 1;
$handler->display->display_options['fields']['nothing']['hide_empty'] = 0;
$handler->display->display_options['fields']['nothing']['empty_zero'] = 0;
$handler->display->display_options['fields']['nothing']['hide_alter_empty'] = 0;
/* Field: Message: Message ID */
$handler->display->display_options['fields']['mid']['id'] = 'mid';
$handler->display->display_options['fields']['mid']['table'] = 'message';
$handler->display->display_options['fields']['mid']['field'] = 'mid';
$handler->display->display_options['fields']['mid']['label'] = 'message_id';
$handler->display->display_options['fields']['mid']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['mid']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['mid']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['mid']['alter']['external'] = 0;
$handler->display->display_options['fields']['mid']['alter']['replace_spaces'] = 0;
$handler->display->display_options['fields']['mid']['alter']['trim_whitespace'] = 0;
$handler->display->display_options['fields']['mid']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['mid']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['mid']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['mid']['alter']['more_link'] = 0;
$handler->display->display_options['fields']['mid']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['mid']['alter']['trim'] = 0;
$handler->display->display_options['fields']['mid']['alter']['html'] = 0;
$handler->display->display_options['fields']['mid']['element_label_colon'] = 0;
$handler->display->display_options['fields']['mid']['element_default_classes'] = 1;
$handler->display->display_options['fields']['mid']['hide_empty'] = 0;
$handler->display->display_options['fields']['mid']['empty_zero'] = 0;
$handler->display->display_options['fields']['mid']['hide_alter_empty'] = 1;
$handler->display->display_options['fields']['mid']['separator'] = '';
$handler->display->display_options['fields']['mid']['format_plural'] = 0;

/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page');
$handler->display->display_options['path'] = 'scribble';

/* Display: Services */
$handler = $view->new_display('services', 'Services', 'services_1');
$handler->display->display_options['path'] = 'scribbles';
frankyn’s picture

Thanks a lot for the help!

I tried out what you said and it gave back correct key values.

Why do capital, spaced, titles not work?

Frank N.

frankyn’s picture

I added the following to the code, to clean it up a little bit. I figure how it's still a view you're not required to make caption specific. I forced the caption to fit the requirement instead.

          $field->options['label'] = preg_replace('/[^0-9a-z_-]*|(\s)*$/', "", strtolower($field->options['label']) );
          if (!empty($field->options['label'])) {
              $new_item->{$field->options['label']} = $output;
          }
          else {
              $new_item->{$field->field_alias} = $output;
          }
frankyn’s picture

Here is your 2b patch + my changes as a patch.

Thanks!

Dippers’s picture

You are using $field->options['label'] before checking whether it exists or not.

frankyn’s picture

Yes! You are right I misplaced the preg_replace().

Attached is an updated version.

Thanks for the feedback.
Frank N.

frankyn’s picture

Hi Dippers,

I was wondering if it would be okay to message you, I'd like to talk a little bit about something I had questions about.

Frank N.

frankyn’s picture

I added additional functionality to your 2b patch but also removed the pre_replace and match because I wanted to allow capitals and spacing inside key's.

The additional functionality is for strip_tags ( ) option inside views. It was operational on the output from services_views. I added in the attached patch.

Frank N.

Jaesin’s picture

Is there any support planned for multi-value text fields or multi-value term references?

Dippers’s picture

This is someway off the original topic but multi-value fields should work. I have multi value term references working using a simple separator.

ianmen’s picture

Quick question: is there also a patch available for Drupal 6 ?

cybertoast’s picture

One addition to this. It seems like there's a limitation in that the services_views is honoring the patch only partially. The view is rendered to take the Rewrite Results into consideration thanks to the patch, but then the Raw vs Rendered handler just subsequent to the view renderer overwrites the values.

The solution, I think, is to replace the following in sevices_views.resource.inc

            ... (around line 171)
            elseif (isset($data['#access']) && $data['#access'] == TRUE) {
              // $obj[$idx] = render($data);
              $rdata = $field->theme($row);
              if (empty($rdata)) {
               unset($obj[$idx]);
              } else {
                $obj[$idx] = $rdata;
              }
            }

I'm not sure this is correct, but the behavior seems consistent with the services_views_retrieve() function's implementation. Could someone please correct me if my logic is wrong, or if this is not the appropriate drupal-ish way to do this.

Also, I'm happy to provide a patch once I get any feedback.

Thanks

Update: I've been adding my code into https://github.com/cybertoast/services_views if anyone finds that more convenient. See the branches for specific implementations.

pippopeppe’s picture

the patch #14 works perfectly for me.

Thanks!

Exploratus’s picture

When I tried to use "Rewrite the output of this field" in views I was getting to output, that was fixed with patch in #14. Thanks! Now I can see the output when using "Rewrite the output of this field".

For reference: https://drupal.org/node/1881112

Dubs’s picture

Thanks for this patch - works well for me.

ajlow’s picture

This patches works for me. Thank you!

One thing I did notice though is that all my empty fields are being placed at the end of the JSON array rather than in the field order I specified in the view.

Is there a way to ensure the order set in the view is kept rather than showing all empty fields at the end?

Actually, should I be concerned with the order of the fields in the JSON array?

yaworsk’s picture

Status: Active » Needs review

Great patch. So far so good, will report back any problems encountered. Thanks for sharingthe solution.

yaworsk’s picture

Category: Feature request » Bug report

Sorry, also, don't think this is a feature so much as a bug since the module doesn't entirely replicate views execution, right?

eojthebrave’s picture

This works for me too. Here's a version of the patch that follows the Drupal coding standards as well as removing lines of code rather then just commenting them out. Thanks!

dmsmidt’s picture

Nice patch (#25)!
Works for me on first glance.
Will report back if I find something strange.

michaelmallett’s picture

This gives me a lot of Warnings, adds hundred per call.

Warning: Cannot use a scalar value as an array in drupal_render() (line 5930 of /Users/MIchael/Sites/zsl/docroot/includes/common.inc).
Warning: Cannot use a scalar value as an array in drupal_render() (line 5985 of /Users/MIchael/Sites/zsl/docroot/includes/common.inc).
Warning: Invalid argument supplied for foreach() in element_children() (line 6465 of

Warning: strip_tags() expects parameter 1 to be string, array given in services_views_execute_view()
Notice: Undefined offset: 0 in services_views_execute_view() (line 219 of etc...services_views.resource.inc)

this is all a bit above my head tbh, I've tried going through the patch but got a little lost

edmargomes’s picture

Hi, it doesn't work for me using solr. I need remove this line:

if (isset($item->{$field->field_alias})) {

because the properties doesn't exist in $item. This line wasn't in the patch #14.

florisg’s picture

updated #28 against latest 7.x-1.x-dev from git (2013-Oct-01)
thanks for sorting this out :)

natuk’s picture

#25 for services_views.resource.inc and #29 for views_plugin_display_services.inc work for me as well.

sergiu.savva’s picture

#29 works for me, thanks ;)

davemybes’s picture

Status: Needs review » Reviewed & tested by the community

I concur: #25 for services_views.resource.inc and #29 for views_plugin_display_services.inc work for me as well. I now see the url alias being output correctly.

kylebrowning’s picture

Status: Reviewed & tested by the community » Needs work

This needs to be re-rolled once again.

michaelmallett’s picture

Am I the only person that gets those warnings, or is everyone else ignoring/suppressing them? I literally get thousands per call and it renders my logs pretty useless.

b_sharpe’s picture

michaelmallett, are you by chance using a reverse relationship (Content entity that is referencing Content via )?

I also am getting just spammed in the logs and as soon as I remove the relationship it works, but yet a page view of the same settings works...

nikunjkotecha’s picture

combined #25 and #29 and modified a bit to get it working for version 7.x-1.1

nikunjkotecha’s picture

updated patch file in #36 to exclude local directories and verified it's working for new drupal install

nikunjkotecha’s picture

d70rr3s’s picture

Hello, I'm don't if is worthy but in my case only works the patch #14 and also I was getting an array of empty stdClasses. I'm with the version 1.1 of Services module

rcodina’s picture

Patch on #37 works for me with Services 3.13 and Services Views 1.1

nikunjkotecha’s picture

Status: Needs work » Needs review
jannis’s picture

#37 worked like a charm for me

jannis’s picture

#37 worked like a charm for me

adolfo.mansilla’s picture

#37 worked like a charm for me

priyanka12chavan’s picture

#37 Worked for me. Thanks Nikunj!!

kylebrowning’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

lily.yan’s picture

About the change in this issue, it strips the tags which aren't allowed to remove all values of location API and service views for location API field is giving NULL values. This fix is under #2907068: Services Views for location field is giving NULL values.