Hi, I ran into the case where the default output of the mlt block is not sufficient and I had to display more fields from a node than just the title in the list output. I have overridden the theme function in my template.php to use a view mode that I defined using the Display Suite module. I thought it might help others if I posted the override I made here.
/**
* Theme recommendation block generated by Apache Solr
**/
function theme_apachesolr_mlt_recommendation_block($vars) {
$docs = $vars['docs'];
foreach ($docs as $result) {
$node = node_load($result->entity_id);
node_build_content($node, 'featured_teaser'); //'featured_teaser' is a custom view mode defined in Display Suite; I think normally only 'teaser', 'full', 'search_result' and 'search_index' are available
$nodes[] = drupal_render($node->content);
}
return theme('item_list', array('items' => $nodes));
}
It might be a nice feature if the block would support view modes by default? The block configuration can still have the option to select a simple list output of titles and next to that an option to use a view mode (with a dropdown to select which view mode to use).
If I find time and it is something that people want, I could make a patch for it
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | 1353422-7.patch | 1.11 KB | nick_vh |
Comments
Comment #1
nick_vhVery interesting!
I'd prefer if this would be a build array so you would be easily able to change that with standard drupal hooks. Please go for a patch and we'll see where we can get from there :-)
Comment #2
nick_vhmerging this into #1356038: More like this / Blocks Admin UI rework
Comment #3
nick_vhOpening again, seems like it didn't make it into the issue from my previous comment. Let's make it happen in this issue
The problem resides in the fact that the module assumes it has to be in a list
A possible solution could be that depending on the item we select a predefined view mode?
Any suggestions?
Comment #4
nick_vhComment #5
nick_vhChange this to a build array
Comment #6
nick_vhComment #7
nick_vhThis should be sufficient for customized work. View modes is a difficult one because there is no clue for us to know what content will appear in the more like this block.
A theming function and a renderable array were added to accomodate for this possibility
Comment #8
nick_vhCommitted
Comment #10
dalinSo if we really wanted to make this configurable, the block settings form would show select fields for each type of entity with options for each view mode that the entity supports. The theme function would then check the entity type of each incoming document, and call the appropriate view function with the configured view mode. This would of course only work for things that are entities, but we could provide a fallback of just a link for those that are not.
Comment #11
stone_d commentedI stuck at the same point of theming the "more like this" output.
Since view modes are very good for theming the node-output, i think dalins apporach would be a good way of implementation. So thumbs up for this suggestion! It would be ok too, to just have one view-mode that the user would have to apply to the entity-type he needs ...
Comment #12
kopeboyCan we make this feature please? I think this is a major one, needed by many users who lack the skill to use custom php code
Comment #13
Khetam commentedThis link also talk about create view mode for MLT block http://pingv.com/blog/improve-your-apache-solr-more-like-this-blocks