I am trying to let my panelized entities get indexed for search. What seemed intuitive to me was to enable the "Search index" view mode on the entity type in question, and then panelize this view mode, substituting it with "Full page override".

However, when I index my content, the "Full page override" view mode (ie., page_manager) is never used. It always uses Default instead.

I think this is because in PanelizerEntityDefault::get_view_mode(), "page_manager" is not found in the "view mode status" array. Perhaps that's because in panelizer_entity_plugin_process() the "page_manager" view mode is assigned after the "view mode status" array is built.

I understand the page_manager view mode is sort of special, so I'm not sure how to resolve this. We could either add special handling in PanelizerEntityDefault::get_view_mode() for the page_manager view mode, or define that view mode earlier in panelizer_entity_plugin_process(). But I don't know what ramifications this will have.

Can you provide any insights on how to replace the search_index view mode with the rendered contents of the page_manager view mode?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

joelstein’s picture

The following code in a custom module also does the trick, in case anyone needs this right away. But I still think this is a bug, since you are able to substitute search_index with page_manager in the UI, so it should also work in the code.

/**
 * Implements hook_node_update_index().
 */
function mymodule_node_update_index($node) {
  // Add Panelized full page content to search index.
  if ($handler = panelizer_entity_plugin_get_handler('node')) {
    $view_mode = 'page_manager';
    if ($info = $handler->render_entity($node, $view_mode)) {
      $build['#view_mode'] = 'default';
      $build['#theme'] = 'panelizer_view_mode';
      $build['#panelizer'] = $node->panelizer[$view_mode];
      $build['#panelizer_content'] = $info;
      $build['#panelizer_handler'] = $handler;
      $build['#panelizer_entity'] = $node;
      $build['#panelizer_bundle'] = $node->type;
      $build['#panelizer_entity_id'] = $node->nid;
      return drupal_render($build);
    }
  }
}
joelstein’s picture

Title: Can't substitute search_index view mode with page_manager » Can't substitute failover default view mode with page_manager
Issue summary: View changes
Status: Active » Needs review
FileSize
22.93 KB
890 bytes

There are several problems with search and Panelizer, but I think for now we can limit this issue to one very specific bug.

In PanelizerEntityDefault::get_view_mode(), if no view mode is found and the fallback 'default' is assigned, we should check if 'default' is configured to be substituted, since this is possible in the UI:

The attached patch fixes this.

joelstein’s picture

Title: Can't substitute failover default view mode with page_manager » Can't substitute failover default view mode
joelstein’s picture

The previous patch still wouldn't allow to substitute non-default view modes with 'page_manager', because 'page_manager' is not configured in the 'view mode status' array.

One solution is to add 'page manager' to that array in panelizer_entity_plugin_process(), which may still be a good idea.

But by simply re-arranging PanelizerEntityDefault::get_view_mode() to fallback to default first, then check for the substitute, we actually resolve both issues: 1) we can substitute when falling back to the default view mode, and 2) we can substitute any view mode with 'page_manager'.

DamienMcKenna’s picture

DamienMcKenna’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Will work on a test for this tomorrow.

DamienMcKenna’s picture

Status: Needs work » Needs review
FileSize
5.94 KB

A patch with some tests to show that the bug exists.

DamienMcKenna’s picture

Both patches combined. In theory this should work.

The last submitted patch, 7: panelizer-n2472519-7.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 8: panelizer-n2472519-8.patch, failed testing.

DamienMcKenna’s picture

This should solve the problem. And I rewrite the logic a little bit to use get_substitute().

DamienMcKenna’s picture

Some other changes accidentally slipped into #11.

The last submitted patch, 11: panelizer-n2472519-11.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 12: panelizer-n2472519-12.patch, failed testing.

DamienMcKenna’s picture

Status: Needs work » Needs review
FileSize
8.77 KB
2.37 KB

Caught the problem - the tests had to pass additional arguments to the content type edit form in order to enable the substitute option.

DamienMcKenna’s picture

Status: Needs review » Fixed

Committed.

Status: Fixed » Closed (fixed)

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