The implementation of template_preprocess_node() in usasearch_api is setting an empty $title variable. Since the variable is being overridden indiscriminately, all templates lose access to the node's $title variable.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

brian.reese created an issue. See original summary.

Barrett’s picture

The code responsible is below (http://cgit.drupalcode.org/USASearch/tree/usasearch_api/usasearch_api.mo...)

<?php
/**
 * Implements hook_preprocess_node().
 */
function usasearch_api_preprocess_node(&$vars) {
  $vars['title'] = '';
  if ($vars['content']['links']) {
    unset($vars['content']['links']);
  }
}
?>
schiavone’s picture

Status: Active » Patch (to be ported)
FileSize
600 bytes

The need to remove titles and links from the rendered content sent to the index was depreciated by adding the option to defining content sent to the index with node displays. Here is a patch that removes the the preprocess function.

Barrett’s picture

Patch works great. Thanks, @Schiavone.

schiavone’s picture

@Barret looking back the idea was to exclude titles and links in the search index returns. Though users could do this by choosing/adjusting a node display we'll want those excluded by default. I'll do some more testing and may have to re-roll.

schiavone’s picture

New patch rolled. Ensure that the node title and links do not get sent to index search results display

  • schiavone committed 9e80676 on 7.x-5.x
    Issue #2858963 by schiavone: Node titles are empty after installing...
schiavone’s picture

Assigned: Unassigned » schiavone
Status: Patch (to be ported) » Fixed

Patch included in 7.x-5.6 release

brian.reese’s picture

@schiavone
The patch rolled into the 5.6 release sets $node->title = '' in usasearch_api_convert_node_to_document(), but this can still be problematic. Particularly, If the $node passed to the function is referenced again, the $node's title will then be empty (PHP Objects and References).

As a concrete example:

$node = node_load($nid);

// Delete the document from the index
usasearch_api_index_document($node, 'delete');

// ...

// Inserting the document should now fail, as $node->title is empty.
usasearch_api_index_document($node, 'insert');

schiavone’s picture

Issue summary: View changes
Status: Fixed » Patch (to be ported)
FileSize
672 bytes

Rolled new patch moving emptying title to a local variable to ensure that the node is not affected.

brockfanning’s picture

Status: Patch (to be ported) » Needs review
FileSize
699 bytes

I don't think this is quite there. Because $view_teaser['#node'] is a reference to the same object, this is still a problem. You can see it in action when indexing a document for the first time - the title is removed once during the DELETE request, and then when it's time for the POST request, it's still gone.

The attached patch is working for me.

schiavone’s picture

$view_teaser is a local variable. It gets deleted once the function completes. So how would any changes be carried over into a separate call?

brockfanning’s picture

It's true that $view_teaser is a local variable, but $view_teaser['#node'] is still a reference to the $node object which originated in usasearch_api_update_index(), and is then passed along to usasearch_api_index_document() and then to usasearch_api_convert_node_to_document(). This happens twice - once for 'delete' and once for 'insert'. Any changes to that $node object that are made during the 'delete' phase will also be in effect during the 'insert' phase.

schiavone’s picture

This patch removes looping through indexing calls in usasearch_api_index_document() and resets the title in usasearch_api_convert_node_to_document().

schiavone’s picture

Status: Needs review » Fixed

Latest patch has been included in 7.x-5.7 release

Status: Fixed » Closed (fixed)

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