We're working on a site where one of the key feature is that users should be able to execute search in user profiles. We're using Display Suit for rendering, Apache Solr for the search and Profile2 for storing user profiles. During the profile search configuration I've found the following issue:

Fatal error:  Call to undefined method stdClass::label() in ../sites/all/modules/contrib/entity/entity.module on line 1066

Proposed solution

I've spent a couple of hours with debugging and found that the following code, in the Display Suit Search module, could cause the issue.

The ds_search module is hooked in the apache solr indexing process and modify the document object by implementing the hook_apachesolr_index_document_build hook and extend the document object with zs_entity field. This field stores the actually indexed entity object as a json encoded object.

 * Implements hook_apachesolr_index_document_build().
function ds_search_apachesolr_index_document_build(ApacheSolrDocument $document, $entity) {
  // Apache Solr multisite support. Render the node already here.
  if (variable_get('ds_search_apachesolr_multisite')) {
    $element = node_view($entity, variable_get('ds_search_view_mode', 'search_result'));
    print drupal_render($element);
    $output = ob_get_contents();
    $document->addField('tm_ds_search_result', $output);
  // Creme de la creme: Put the full node object in the index,
  // so no node_loads are needed for results in the Apache Solr engine.
  // We are using zs_entity because this field is not indexed by apachesolr and it
  // is a single.
  $entity_type = $document->getField('entity_type');
  $entity_id = $document->getField('entity_id');
  $entity_type = $entity_type['value'];
  $entity_id = $entity_id['value'];
  $entities = entity_load($entity_type, array($entity_id));
  $entity = reset($entities);
  $json = drupal_json_encode($entity);
  $document->addField('zs_entity', $json);

While processing the solr response the ds_search module deserialize the zs_entity field's value with the following code.

      $entity = @drupal_json_decode($result['fields']['zs_entity']);
      if (empty($entity)) {
        $load = entity_load($result['fields']['entity_type'], array($result['fields']['entity_id']));
        $entity = reset($load);
      else {
        $entity = (object) $entity;

Since the code above is just cast the $entity array to a simple stdClass object the $entity won't act as a standard Entity object. The entity functions won't be accessible that comes with inheritance. This could cause that the label method is not exists.

Remaining tasks

I'm not sure the purpose of the zs_entity field, so there might be some use cases that I've missed.

Members fund testing for the Drupal project. Drupal Association Learn more


hairqles’s picture

swentel’s picture

Status: Active » Closed (duplicate)