Task description
This task is to modify the FAQ module so that it uses theme templates instead of 4 of its theme functions.

Modules in Drupal have the ability to allow their HTML presentation to be overridden by the theme layer. This gives a huge amount of flexibility and allows greater customisation of Drupal sites. In Drupal 5, "theme" functions were used to contain chunks of HTML output which could be overridden. This method is still supported in Drupal 6 but there is now an alternative and better way of implementing it using template files.

The FAQ module has a number of theme functions. To complete this task, you need to create a template file (.tpl.php) and a corresponding preprocessor function for each of the theme functions listed below. See the resources section for more information, particularly "Using the theme layer in Drupal 6".

Theme functions:

  • theme_faq_new_page()
  • theme_faq_hide_answer()
  • theme_faq_questions_inline()
  • theme_faq_questions_top()

The final deliverable will be a patch against the 6.x version of the FAQ module posted to the issue queue that has been reviewed and marked "Ready to be Committed".

Resources

Primary contact
Stella Power (http://drupal.org/user/66894 - snpower)

Comments

stella’s picture

cwgordon7’s picture

Assigned: Unassigned » cwgordon7
Status: Active » Needs review
StatusFileSize
new851 bytes
new9.24 KB

This needs review. Sorry that the template files are zipped, but my patcher program was giving me trouble :(.

Any feedback would be appreciated.

-cwgordon7

cwgordon7’s picture

StatusFileSize
new1.46 KB
new9.18 KB

Updated version, rerolled.

cwgordon7’s picture

StatusFileSize
new1.44 KB
new8.95 KB

Sorry, windows line endings.

aclight’s picture

Status: Needs review » Needs work

As I mentioned in IRC, I really know nothing about D6 theming, so what I write below may or may not be helpful. I also didn't have time to actually test this to confirm that it works. Most of these are pretty minor points, but probably should be addressed.

A.) You change several comments to have a capital letter. You might as well fully comply with the Drupal coding standards and add a period at the end to make it a sentence. :)

B.) Looks like you kept a comment that's unnecessary:

-  $output = "<div>\n";
+  // $output = "<div>\n";

C.) It seems to me that this:

+  foreach ($nodes as $key => $node) {
+    $tmp = $node['link'];
+    $tmp .= $node['body'];
+    $nodes[$key]['themed'] = $tmp;
+    $output .= $tmp;
+  }
+  $variables['output'] = $output;
+  $variables['nodes'] = $nodes;

would be better as:

+  foreach ($nodes as $key => $node) {
+    $nodes[$key]['themed']  = $node['link'] . $node['body'];
+    $variables[output] .= $nodes[$key]['themed'];
+  }
+  $variables['nodes'] = $nodes;

but I could be wrong.

D.) In faq-questions-inline.tpl.php, you have this:

  <font color="#6e0dd3">
  <?php print $node['link']; ?>
  </font>

Shouldn't you just apply a style in the tpl.php file and then include a separate .css file that defines the style's attributes?

Also, as discussed on IRC, this really should be made into one patch if possible so that it's easier to review.

cwgordon7’s picture

StatusFileSize
new8.88 KB

Ok.

(a) is easy enough, done.
(b) Grr. I hate it when I do that :(.
(c) Ugh. How could I not see that?
(d) The point of a template file is to make it easy to edit; html is user-friendly (ish), while css is not. The <font color="#6e0dd3">could easily be replaced with <strong>, or whatever the admin wants.

And, I'm still having trouble getting it into one patch. I'm really sorry, but the template files still have to be zippified. Since I made no updates to them, the older version of the templates will work fine. New patch is attached.

aclight’s picture

I don't see how css is not user friendly, and personally I wouldn't commit code with specific styles in the tpl.php file, but since I'm not committing anything here, so it's up to the module's maintainer as far as what to do about that.

cwgordon7’s picture

Status: Needs work » Needs review
StatusFileSize
new1.43 KB

New templates attached in response to aclight's post.

stella’s picture

StatusFileSize
new551 bytes

Sorry for the delay in responding, I've been internet-less since Christmas.

So I've done a quick test of the patch and the initial feedback is below. However I did find one bug in the original checked-in code! There was a missing closing " for a class name which broke the faq node links in the questions inline mode. I've checked in the fix and attached a patch for your version.

My initial tests just involved testing of (a) the functionality and (b) the layout, i.e. basically that it behaves and looks the same as the previous version.

  • faq-new-page.tpl.php: there should be no <h4>...</h4> tags in this file as it messes up the font size.
  • faq-hide-answer.tpl.php: there is an extra <hr> tag on line 18 which shouldn't be present.
  • faq-questions-inline.tpl.php: there are extra <strong>...</strong> tags around the question text which cause it to display incorrectly.
  • faq-questions-top.tpl.php: there is an extra <hr> tag on line 12.

I'll conduct a more in-depth set of tests next. However, it's looking great! Thanks a mill!

Cheers,
Stella

stella’s picture

Hi,

I've had another look at the patch, at the code this time. I quite like what you've implemented with the different variables available to the themer in the template file, especially the way that they're clearly documented. However, I would prefer if all of the html divs could be moved out of the module file and into the template files.

Here's an example:

      $nodes[$count]['link'] = '<div class="faq_question faq_dt_hide_answer">';
      $nodes[$count]['link'] .= l($node->title, "node/$node->nid") ."</div>\n";
      // should we display teaser or full text
      if ($display_vars['use_teaser']) {
        $more_link = '';
        if (!empty($display_vars['more_link']) && strlen($node->teaser) < strlen($node->body)) {
          $more_link = '<p class="faq_more_link">';
          $more_link .= l(t($display_vars['more_link']), "node/$node->nid") .'</p>';
        }
        $nodes[$count]['body'] = '<div class="faq_answer faq_dd_hide_answer">';
        $nodes[$count]['body'] .= check_markup($node->teaser, $node->format, FALSE);
        $nodes[$count]['body'] .= $more_link ."</div>\n";
      }

      // full text
      else {
        $nodes[$count]['body'] = '<div class="faq_answer faq_dd_hide_answer">';
        $nodes[$count]['body'] .= check_markup($node->body, $node->format, FALSE) ."</div>\n";
      }

could change to something like:

      $nodes[$count]['link'] = l($node->title, "node/$node->nid");
      // should we display teaser or full text
      if ($display_vars['use_teaser']) {
        $more_link = '';
        if (!empty($display_vars['more_link']) && strlen($node->teaser) < strlen($node->body)) {
          $more_link = l(t($display_vars['more_link']), "node/$node->nid");
        }
        $nodes[$count]['body'] = check_markup($node->teaser, $node->format, FALSE);
        $nodes[$count]['more_link'] = $more_link;
      }

      // full text
      else {
        $nodes[$count]['body'] = check_markup($node->body, $node->format, FALSE);
      }  

See the way all of the <div> tags have been removed. It could be that the themer doesn't want to use div tags around the answer text and instead wants to use <p> tags instead. You will need to modify the template files as appropriate. It will probably involve the use of a foreach loop but I think that's an acceptable amount of php code in a template file. See some of the forum module's template files for examples.

Cheers,
Stella

cwgordon7’s picture

StatusFileSize
new1.37 KB
new8.88 KB

Thanks for the review :)

New re-rolled patch and templates attached. The extra formatting in the templates was supposed to be an example of what you can do with templates for the user, but it seems that it is not necessary, so I removed the extra html.

cwgordon7’s picture

Whoops, I posted the comment while you were reviewing. This was in response to #9. Give me a few minutes to respond to #10.

cwgordon7’s picture

StatusFileSize
new1.92 KB
new10.45 KB

Ok, new patch & templates attached. :)

dmitrig01’s picture

Couple of comments:

  1. Don't use the foreach() {...} structure in a template. That's just plain BAD.
    Instead, use
    foreach():
    ...
    endforeach;
    

    That's the syntax most often used in Drupal

  2. ?>
    <div>
    

    That shoulud be on the same line, like this:
    ?><div>

  3. /**
     * $que_label represents the question label.
     * $ans_label represents the answer label.
     */
    

    Why que and ans? why not question and answer?

  4. In faq-hide-answer.tpl.php, why not just have a <dl>?
  5.  * $list_style represents the style of the list.
    

    I don't get that. Could you make it more clear?

  6. In faq-questions-top.tpl.php, why do "conditional variables" get their own section? why not just state that it's a conditional variable in the doc
  7. What's all this display_vars stuff?
  8. Why isn't theme_faq_category_questions_top a template? it seems to be a lot of html mixed with php.

[/review]

stella’s picture

dmitrig01: answers to some questions below:

Q.1, good point, though I'm not sure that it's done that way in the forum module, maybe we need to add a minor bug report for that, or add a check to the coder module so it can check for it in future?

Q.3, again good point, I think it was probably inherited from the original version of the code, but the variable name should be made clearer.

Q.5, users can choose between ordered lists (<ol>) and unordered lists (<ul>). The $list_style variable probably contains ul or ol.

Q.7, display_vars stuff is inherited from the original version of code. I don't think modifying this should fall into the scope of this GHOP task.

Q.8, theme_faq_category_questions_top isn't a template because we haven't gotten that far yet. I thought it was too many functions to port to a template for one GHOP task. As soon as this task is completed, I'll open a 2nd task that ports this function, and others, to templates.

Cheers,
Stella

cwgordon7’s picture

StatusFileSize
new1.95 KB
new10.59 KB

Ok, new stuff attached.

stella’s picture

Hi,

Did another review of the patch. It's almost there. The only things left are minor layout and coding standards changes.

faq-new-page.tpl.php
Perfect!

faq-hide-answer.tpl.php

  • The more link should be printed within the <div class="faq_answer faq_dd_hide_answer">...</div>.
  • Some of the indentation in the corresponding preprocess function is incorrect, lines 1147 and 1153 (tabs are used instead of spaces).
  • Line 21 of the template file, change this line to use !empty($node['more_link']) function rather than checking $node['more_link'] != ''.

faq-questions-inline.tpl.php

  • Both the "more" and "back to top" links should be printed within the <div class="faq_answer">...</div>.
  • The answer label should be within a <strong>...</strong> pair of tags in order to match the original layout.
  • Line 27 of the template file, change it use to use php's empty() function instead of isset().
  • Indentation on line 30 of the template file uses tabs instead of spaces.

faq-questions-top.tpl.php

  • Line 874, in the corresponding preprocess function, breaks the Drupal coding standards - it uses a tab instead of a spaces.
  • The question text that is printed just above the answer (i.e. not the ones in the list) is contained within the <div class="faq_answer"> section instead of it's own <div class="faq_question"> section.
  • Again both the "more" and "back to top" links should be printed within the <div class="faq_answer">...</div> section.
  • I might also suggest that you use <br /> or something similar just to add a wee bit of blank space between the question list and the Q&A text further down. This is only a minor thing though.

Here's what the html structure of the resulting faq page should follow:

<div class="faq">
  <div class="item-list">
    <ul class="faq_ul_questions_top">
      .........
    </ul>
  </div>
  <div class="faq_question"><a href="/node/126" name="n126">How do I edit my personal details?</a></div>
  <div class="faq_answer">
    <p>abcde</p>
    <p class="faq_top_link"><a href="/faq" class="active">Back to Top</a></p>
  </div>
  <div class="faq_question">............</div>
  .........
</div>

Each of the template files also need to have the CVS keyword $Id$ included in each file, e.g. /* $Id$ */.

You're pretty much there at this point. There's only a few minor changes left to make at this point. Well done!

Cheers,
Stella

cwgordon7’s picture

StatusFileSize
new2.03 KB
new10.55 KB

Thanks, revised stuff attached.

dmitrig01’s picture

Ok, my turn for a review

In templates, with $Id$ tags, those go (a) in comments marked by //, (b) in the same block of PHP as the other comments/docs
Example:
/* $Id$ */

/**
 * Available variables:
 *
 * $questions_list represents a list of questions based on $list_style.
 * $list_style represents the type of list.
 * $limit represents the number of items.
 * $answers represents an array of answers.
 *   $answers[$key]['link'] represents the link to the node.
 *   $answers[$key]['body'] represents the body of the node.
 * $questions represents an array of questions.
 * $back_to_top rep

should be

// $Id$

/**
 * Available variables:
 *
 * $questions_list represents a list of questions based on $list_style.
 * $list_style represents the type of list.
 * $limit represents the number of items.
 * $answers represents an array of answers.
 *   $answers[$key]['link'] represents the link to the node.
 *   $answers[$key]['body'] represents the body of the node.
 * $questions represents an array of questions.
 * $back_to_top rep

That IMO is the only outstanding issue!

stella’s picture

Yep, the issue dmitrig01 identified above is the only outstanding issue! Everything else is perfect.

Cheers,
Stella

cwgordon7’s picture

StatusFileSize
new2.02 KB

Ok, revised templates attached.

stella’s picture

Status: Needs review » Reviewed & tested by the community

Perfect! It's great! Thanks for all your hard work. I really appreciate it. Good luck with your other GHOP tasks.

aclight, dmitrig01: would one of you mind updating the Google issue: Issue 108.

Cheers,
Stella

add1sun’s picture

GHOP issue is closed. Thanks cwgordon7!

stella’s picture

Status: Reviewed & tested by the community » Fixed

All checked in! Thanks again.

Cheers,
Stella

Anonymous’s picture

Status: Fixed » Closed (fixed)

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

stella’s picture

Released in FAQ 6.x-1.3.

Cheers,
Stella