Closed (fixed)
Project:
Search API Pages
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
18 Oct 2011 at 19:42 UTC
Updated:
23 Jul 2013 at 15:41 UTC
Jump to comment: Most recent file
Comments
Comment #1
tomogden commentedHere's an update. I found the $pager variable was not actually defined, so I have added it to the variables array, so someone like me can add a pager to the top of the search results.
Comment #2
drunken monkeyYour patches are both empty.
In general, I fully support this issue, though.
Comment #3
tomogden commentedI guess after I committed the changes there was nothing left to diff for the patches. Are you able to see the commits? Or should I be submitting my changes another way?
Comment #4
drunken monkeyNo, I can't see your local commits. Please read the documentation on how to create patches with Git.
Comment #5
tomogden commentedI backed out all 4 layers of commits by repeatedly running git reset --hard. Then I re-entered my changes from a saved copy and generated the attached patch--guaranteed to NOT be empty. :)
Documentation doesn't say much about this stuff, but I've put together a list of "rules" or best practices for myself, based on this. I hope I'm getting all this correct.
Comment #6
drunken monkeyStill not quite, sorry. Your patch doesn't include the template files themselves.
You can easily test this by applying the patch in reverse mode (with
git apply -R foo.patch) and seeing if that leaves you with a clean module (git statusreturns no changes).I'll give you a quick overview of how to create patches with Git – but usually, please consult the documentation here on Drupal.org. I think the people made a pretty good job documenting the use of Git for Drupal development.
So, if you want to create a patch for a module (no matter whether your own or another one's – as long as you don't want to commit it, but just create a patch file, there's no difference) you have two ways to do that: either just making all changes without committing, or committing all changes like normal.
In the first variant, do the following to create a patch of ALL changes in your local copy of the module:
To only add the changes of some files:
When you want to use commits like normal, you should create a new branch for your local work:
If you have worked and committed on the 7.x-1.x branch, you can still create a patch:
git diff origin/7.x-1.xAlso, you don't have to undo commits one by one, but can use, e.g.
git reset HEAD~4to undo the last four commits (while not changing any files). To also change the files, use
git reset --hard HEAD~4Comment #7
tomogden commentedSomehow forgot to add my templates--poor housekeeping on my part. See new patch attached.
I want to thank you for not censuring me for my error and for taking the time to give me that wonderful mini tutorial. The info you provided led me to find (finally) a very useful Git reference at http://gitref.org/basic/ that pointed out some facts I had always wondered about, like 'where does the repository reside,' 'what is the relationship between repositories' and 'how can I used branching.'
Your information is invaluable and is posted in my personal Evernote repository, along with my notes from the reference I found. Hopefully this issue will be useful to others wondering about Git or who are similarly Git challenged as I.
Comment #8
drunken monkeyGlad I could help!
Now for a review of the actual code … I'm afraid to say that it's not really how these things should be done. I can't blame you, though, the documentation I could find of the Theme API is more like a really, really bad joke.
search_api_page_results_pagetemplate for that.ifs with single-variable conditions, loops andrender()calls are generally OK (and maybet()calls, if it's clearer that way), but almost anything else isn't. Make the variables you pass to the template complete render arrays (in the preprocess functions) and only callrender()on them, instead of theming/viewing right in the template.<li>element in both templates, thus wrapping each search result twice (leading to invalid HTML and display problems).render(), not function calls (only variables should be passed by reference).search-api-page,search-api-page-{$page->machine_name}, etc.). Or, all created elements should have these classes (probably not too hard to do by using one$classesarray and passing that on to the „lower“ functions.).This will include the CSS file in all pages, not only when viewing search results.
Don't know why you changed this, the view mode is still named
search_api_page_result.So, in the big picture, I'd do the following:
$additionalvariable or something like that), pager, etc. into one render array with'#theme' => 'search_api_page_results_page'(or something like that).template_preprocess_search_api_page_results_page()pass the results totheme('search_api_page_results')with the necessary additional information.template_preprocess_search_api_page_results_page()take care of rendering the individual results in the appropriate way. Thesearch-api-page-resultstemplate (which is, by the way, what I think it should be called, not with underscores) should preferably only receive a single$resultsvariable to output, containing a render array.That's about it.
Please use the attached patch as the starting point for future work – it fixes some of the smaller issues, and applies cleanly to the current HEAD (with #1285116: Results per Page _GET Override already committed).
Comment #9
harrrrrrr commentedAny update on this? Currently the search page has no pager.
Comment #10
tomogden commentedWorking on the corrections now. Apologize for the hiatus. Should have something this week.
Comment #11
rooby commentedAnother thing that could be added to this to greatly benefit themeing is to add template suggestions.
It would be desirable to be able to override the template at the index level because you might be returning greatly different results from each index.
Comment #12
tomogden commented@Drunken Monkey, I've gone through all your recommendations. While I still have questions, this should be a good point to review and move a little forward.
Removed this code block form the hook_view() function.
Spellcheck is now moved out to the template. However, the shouldn't the render array be setup in the spellcheck module?
I count a total of 5 elements so far, which doesn't seem like a lot. Think about this later on?
Thank you for educating me there. The foreach is moved to the preproc, and it is much simpler.
Excellent suggestion to translate everything to renderable arrays. I've affected the change for everything in the results (multiple) template except the pager, which is generated by a theme() call in the hook_view() function.
Right, that seems to have gone away in this version, but I will defer to your test findings.
That seems to have disappeared in my rendering construction. I've added some first/last, even/odd classes.
Done.
Eliminated, now that we're working on the new base.
I've added the
According to documentation at http://drupal.org/node/171209, the [all] index refers to the media type, as in 'screen', 'projection', 'print'. I find no option to restrict the stylesheet to any URL.
Odd. I have changed it back. It seemed logical at the time to refer to the plural, but it's a minor point.
Calling theme() in template_preprocess_search_api_page_results_page() will render the elements there, right? So that all you pass to the template are string variables. Is that what you wanted?
Putting everything into a single render call sort of defeats the purpose of a template, doesn't it? Don't you want to expose the render elements individually? With individual render functions?
I have renamed the templates with dashes.
Comment #13
ajaysolutions commentedHey just been looking, is there a way to do this so that the blocks can be themed as well? I want to add some divs to the block...
Comment #14
rooby commented@ajaysolutions:
Can you be a little more specific about what you mean by "the blocks"? Just to be clear.
Comment #15
guillaumev commentedI tested this and it seems like it's working fine... Would love to see this committed :-) ...
Comment #16
tomogden commentedGiven the number of changes to this project's code, I have updated the patch. I have also removed any of the 'housekeeping code' not directly related to this issue and posted it under another inconsequential issue.
If @guillaumev or someone would like to review it again, that would be very helpful.
Comment #17
bachbach commentedHi thanks for the work,
i patched and quickly tested the template system, it seems to work for now, excepte in search-api-page-results.tpl.php L44
you forgot a "php" : "<?" -> "<?php"
Comment #18
guillaumev commentedI tested as well and it's working. I'm just providing a new patch which fixes the error mentioned in #17.
Comment #19
guillaumev commentedComment #20
mollux commentedI tested it too and works well.
I really need this this for the Search API location module!
Comment #21
sutharsan commentedJust finished my theme function overrides yesterday, only now I discover this issue. Would love to see this committed!
Comment #22
drunken monkeySorry, I was already reviewing the day before yesterday but then this happened: #735606: Let the user confirm before canceling.
So now a somewhat shortened review, sorry.
First off, many thanks to all of you for the great patch and your work!
Typos / misspellings:
In „View mode“, the m should be lower case.
You wrote several times search_api_page-results.tpl.php instead of search-api-page-results.tpl.php in comments.
Warnings I got:
Notice: Undefined index: keys in theme_search_results_list() (line 155 of …/search_api_page/search_api_page.module).
Notice: Undefined index: excerpt in template_preprocess_search_api_page_result() (line 166 of /home/thomas/Dokumente/Programmieren/PHP/Drupal/search_api_page/search_api_page.pages.inc).
Strict warning: Only variables should be passed by reference in include() (line 45 of /home/thomas/Dokumente/Programmieren/PHP/Drupal/search_api_page/search-api-page-results.tpl.php).
Please remove the specific references to node / user and replace with “if available” and the like.
I think this should only reference our preprocessing function, not those three.
Why not just
$classes?Also, don't include the
class="…"parte here, just include the classes themselves.Please pass the full page object, I don't see a reason to just pass the machine name.
Use a
$classesvariable here, prepared in the preprocessor, and usingdrupal_clean_css_identifier().For my taste, this is too much logic for a template file. Do this in the preprocessing function, please!
This will add the CSS file to every page. Please revert to using
drupal_add_css().These theme function names should be properly namespaced (i.e., prefixed with
search_api_page).There should be a newline between those two lines.
Also, more importantly: Do we really need this? Can't we just use
theme_list()? What do we gain? This should also be explained in the doc comment.Comment #23
tomogden commentedChanges made--total of 15 items. See patch attached.
Comment #24
drunken monkeyIt seems you just removed the
search_api_page_search_results_list()function, but still reference it in your code (hook_theme()andtemplate_preprocess_search_api_page_results()). Can this be just replaced by the normallisttheme?Also, the handling of the classes doesn't make any sense – you don't set those at all, only locally in one preprocessing function. They aren't passed on to any template.
First setting
$variables['search_results']if it might be overwritten later (if a real view mode is used) also doesn't make much sense.There were also a number of still unfixed typos/ommission I fixed in the attached patch.
And again some notices:
Next time, could you please review your patch (or at least test it) before submitting?
I also suggest we use
search_api_page_results__{$page->machine_name}as the theme, so site builders can override that on a per-page basis.Comment #25
tomogden commentedOkay, thanks, @drunken monkey, it's been a year since I put the original patch together and was a little out of touch. The sites I was testing on did not test it thoroughly enough.
Working on a replacement patch...
Comment #26
aaronbaumanJumping into this thread late, but I've rolled an updated patch based on the feedback from #24
Comment #27
tomogden commentedGreat job, Aaron! Just when I was about to go back to this, you've covered every item. I especially like the way you adapted the $item objects to work in item_list.
I noted the templates were doubled up in each file. I have stripped out the redundant code and attached the rerolled patch here.
Comment #28
petergus commentedReally great to find this. One question, the combo patch in #27 doesn't apply to dev, only to beta2, should this be so?
I have one slight patch to submit.
I moved the form to render in the template itself. Would this be a good way to do it?
Comment #29
rooby commentedIt should really be for dev.
Comment #30
petergus commentedmy patch seems like a totally bad way to do this... does anyone have an idea to move the form render out of inc to tpl?
Comment #31
drunken monkeyAttached is a re-roll that should apply to current dev. Please test/review so we can finally get this in!
You'd have to pass the rendered form inside a variable. However, I'm not sure we should do this, the form isn't really part of the results. And users already get the option of excluding the form from the results page. Other changes can probably be as easily achieved with altering the returned render array, or just with CSS.
Comment #32
drunken monkeyRe-roll for latest dev.
Could someone please take a look / test so I can commit this? I'm not a themer, so I'm not confident enough that the patch should be committed like this.
Comment #33
aaronbauman#32 works functionally, but i can't comment about theming either.
Comment #34
travisc commentedI like the templates, but i think it's overkill to force the search result to be a ul li list. Just render $search_results with no markup, I'll add whatever else i need to the templates.
Comment #35
rooby commentedWithout me reading through all the code right now, does anyone know why this is using custom templates instead of drupal core's search-result.tpl.php and search-results.tpl.php.
It seems like re-inventing the wheel and adding unnecessary things to the theme registry to be making new templates.
Also, it is easier for themers if search results from all types of search modules use the same result templates.
I'm pretty sure all the search modules I have ever used use the default drupal core templates.
If no one else gets to it before me I might do a patch that uses the core templates for comparison.
I'm all for clean markup but from a semantics and accessibility point of view the search results really are a list. As long as it isn't wrapped in a bunch of unnecessary divs I don't think that a single ul is excessive markup.
If everything else in drupal core and contrib was spartan by default I could understand but that is not the case.
I think it is correct to make it a list and if you don't want that then you remove what you don't want from the templates.
This means users without the skill to modify templates get nice semantic markup.
Comment #36
drunken monkeyI agree with rooby there, they are a list so the correct semantic list to output them is with a list.
In theory, it's even an ordered list – maybe that would be the right thing here? I just checked, core search does it the same way, so I vote for changing the list type to
<ol>. Patch (with a one-character change compared to #32) attached.@ rooby: We don't depend on core search and shouldn't, so we can't use their theme functions and templates – that's it. Also, the templates in this patch are actually based on the ones in core, see the original post. While it's certainly code duplication (though, as said, necessary one), there was no real duplication of effort.
Anyways, great to hear some positive feedback here. If there are no further objections (also against the
<ol>change), I can soon finally commit this.Comment #37
drunken monkeyOh, I think now I see what you mean, travisc: you mean the
<ol>and<li>should be inside the templates instead of the search results being wrapped in an additionaltheme_item_list(), so you can decide not to use a list more easily.That's of course true and also what core does, and I don't really know why it wasn't like this before. See the attached patch for a fix.
I hope now everything's fine. Thanks for complaining about this! ;)
Comment #38
drunken monkeyAaaaaand finally committed!
Phew.
Thanks again for everyone's work, especially tomogden for his continued effort!