I've taken an initial pass at a Drupal 7 port for faq, which passes coder tests and has a working node form, but not much more. Attached is a patch against the latest D6, which I hope provides a useful basis for a D7 branch.

Comments

sreynen’s picture

Status: Active » Needs review

Changing status.

stella’s picture

Assigned: Unassigned » stella

Oooh, thanks! will review soon.

stenjo’s picture

I'm checking this out at the moment (Working on a D7 version of FAQ_Ask and need this).

Seems like D7 does not like drupal_install_schema('faq'); at line 47 in faq.install. D7 installs the tables if hook_schema() is defined.
Ref http://api.drupal.org/api/function/hook_install/7

In addition, the check_markup() has changed in D7 and expects other parameters.
$node->detailed_question = check_markup($node->detailed_question, $node->format, FALSE); line 389, faq.module
Changed to
$node->detailed_question = check_markup($node->detailed_question);
Ref. http://api.drupal.org/api/function/check_markup/7

hook_view has also changed (http://api.drupal.org/api/function/hook_view/7)

rorymadden’s picture

Status: Needs review » Needs work

Subscribing. Has any progress been made on this yet?

BenK’s picture

Subscribing...

bfsworks’s picture

Trying to install FAQ_Ask which had a D7 port but is dependent on this module. Any testing, patches, or updates?

vikingew’s picture

I see that work has started be commit into CVS, can it also be hooked up to have dev releases pushed out, please? Hide it if feel need to but make it available under all releases.

mxt’s picture

I need this fantastic module for Drupal 7 too.

Hope to see a dev 7 version soon...

Thank you very much for your work!

MXT

deminy’s picture

I wish that the D7 version will come out soon. Thanks

stenjo’s picture

@MXT @deminy, I have a feeling the chances for a D7 version of this module increases somewhat if you are able to offer some form of help in moving the code to an updated version. I think any help would be valuable - even if all you can do is testing it...

drupa11y’s picture

I could offer help in testing, html & css.

willvincent’s picture

Status: Needs work » Needs review
StatusFileSize
new19.96 KB

Here's a patch against the D7 version in cvs. (NOT the 6.x-1.x-dev version!)

This should address a couple minor issues with JS & the filter format setting in the admin include file.

Edit: attachment link doesn't seem to be working right.. http://drupal.org/files/issues/faq-762152.patch

drupa11y’s picture

I would like to test it but I don´t understand how to check out the branch with cvs on os x, sorry.
Can anyone provide a cvs-command to copy and some short instructions or is there a gui-client and a tutorial somewhere?

Thanks!!!

BenK’s picture

@mori: Follow the instructions here: http://drupal.org/project/faq/cvs-instructions

Just choose from the dropdown the version you want to check out (6.x-1.x-dev).

Then just cut and paste the command into the Terminal program on Mac OSX.

--Ben

drupa11y’s picture

Thank you!

Tilt_11’s picture

Subscribing...Any chance you would consider including the functionality of faq_search (no longer maintained) in faq-7.x?

mikejoconnor’s picture

StatusFileSize
new21.14 KB

Here's an updated patch. I removed some dpm' and added the following.

@@ -247,9 +246,7 @@ function faq_form($node, $form_state) {
 
   // Answer.
   if (!empty($type->body_label)) {
-    dpm(__LINE__, __FUNCTION__);
-    $form['body_field'] = node_body_field($node, $type->body_label, $type->min_word_count);
-    $form['body_field']['body']['#description'] = t('This is that answer to the question.  It will be filtered according to the input format.');
+    field_attach_form('node', $node, $form, $form_state, $node->language);
   }
 
   return $form;

I haven't tested all of it, we will be doing that over the next couple days.

mikejoconnor’s picture

StatusFileSize
new22.02 KB

Here's an update to patch #17, which adds the following items to hook_filter_info()

/**
 * Implements hook_filter_info().
 */
function faq_filter_info() {
  $filters['faq_embed'] = array(
    'title' => t('Embed FAQ page'),
    'cache' => FALSE,
    'description' => t('Embed FAQ page using [faq] type tags.  Disables filter caching so not recommended for all input formats.'),
    'tips callback' => 'faq_filter_tips_faq_embed',
    'process callback' => '_faq_filter_process',
    'settings callback' => '_faq_filter_settings',
  );
  return $filters;
}

function _faq_filter_settings($form, &$form_state, $filter, $format, $defaults, $filters) {
  return array();
}
jamesoakley’s picture

subscribe

drupa11y’s picture

The try to ad a faq (/node/add/faq) fails with the D7 v1.0 release:
Fatal error: Call to undefined function node_body_field() in /Applications/MAMP/htdocs/drupal-7.0/sites/mori.d7.dev/modules/content/faq/faq.module on line 251

Also I could not use "admin/config/faq":
Fatal error: Call to undefined function filter_form() in /Applications/MAMP/htdocs/drupal-7.0/sites/mori.d7.dev/modules/content/faq/faq.admin.inc on line 47

The 2 patches from above did not help to this issues.
FAQ was latest cvs checkout.

Got also an error with the 2nd patch:
mori-mbp-17:faq mori$ patch < faq-762152-2.patch
patching file faq.admin.inc
Reversed (or previously applied) patch detected! Assume -R? [n] y
patching file faq.js
Reversed (or previously applied) patch detected! Assume -R? [n] y
patching file faq.module
Reversed (or previously applied) patch detected! Assume -R? [n] y
Hunk #3 FAILED at 1542.
1 out of 3 hunks FAILED -- saving rejects to file faq.module.rej
mori-mbp-17:faq mori$

drupa11y’s picture

***************
*** 1539,1558 ****
*/
function faq_filter_info() {
$filters['faq_embed'] = array(
- 'title' => t('Embed FAQ page'),
- 'cache' => FALSE,
'description' => t('Embed FAQ page using [faq] type tags. Disables filter caching so not recommended for all input formats.'),
'tips callback' => 'faq_filter_tips_faq_embed',
'process callback' => '_faq_filter_process',
- 'settings callback' => '_faq_filter_settings',
);
return $filters;
}

- function _faq_filter_settings($form, &$form_state, $filter, $format, $defaults, $filters) {
- return array();
- }
-
function _faq_filter_process($text) {
$text = preg_replace_callback('/\[faq:?([^\]]*)\]/', '_faq_faq_page_filter_replacer', $text);
// Remove comments, as they're not supported by all input formats.
--- 1542,1556 ----
*/
function faq_filter_info() {
$filters['faq_embed'] = array(
+ 'name' => t('Embed FAQ page'),
+ 'no cache' => TRUE,
'description' => t('Embed FAQ page using [faq] type tags. Disables filter caching so not recommended for all input formats.'),
'tips callback' => 'faq_filter_tips_faq_embed',
'process callback' => '_faq_filter_process',
);
return $filters;
}

function _faq_filter_process($text) {
$text = preg_replace_callback('/\[faq:?([^\]]*)\]/', '_faq_faq_page_filter_replacer', $text);
// Remove comments, as they're not supported by all input formats.

stella’s picture

These patches and other changes have been committed. Testers needed though, so please download today's dev version and see if it all works as you expect - especially the categorised listings.

boftx’s picture

subscribe

boftx’s picture

I downloaded the dev file available at 21:30 PST and found the following (this is not a complete test but should be a start.)

Install and enable went smooth, that's encouraging. :)
Basic config went pretty much as expected.
In the permissions block the permisson "Edit own FAQ nodes" shows up twice. I presume one of those was meant to be "Edit ALL FAQ nodes"

The problems started when I tried to categorize questions. Tests were performed with a single question and a single term under the manually created vocabulary "FAQ"

Basically, once I created the vocab, I started seeing the following error message with categorze questions disabled but with the vocab included in the config list.
"Notice: Undefined offset: 3 in faq_page() (line 552 of /sites/all/modules/faq/faq.module)."

When I enable the categorize questions I started to see this error every time I went to the /faq link.
"Fatal error: Call to undefined function taxonomy_term_count_nodes() in /sites/all/modules/faq/faq.module on line 575"

I added a new field to the FAQ content type to pull in the FAQ vocab, and made it optional. After editing the existing question at the node level I continued to see the fatal error above.

Disabling categorize questions removed the fatal error, as did excluding FAQ on the config page. However, excluding the FAQ vocab with categorize enabled resulted in no question being listed.

Could this be related to the fact that there is no option to display uncategorized questions such as was present in the D6 version?

boftx’s picture

Further info. Choosing the option to NOT show category labels, with categorize enabled, does NOT produce the fatal error. Also, the question appears whether it has been assigned a term or not.

I may be testing a pathological border case, so I will test further with more than one question and more than one category.

Also, I found it VERY tedious to set up the categories, having had to create a vocab, and then excluding all but that one, and also having to add a custom taxinomy field to the content type. I guess this is a result of changes to the D7 core, but it sucks just the same. This implies that the module should create the Taxinomy vocab with one default term ("General"?) and the CCK field for it already installed in the content type.

I would also suggest having the config automatically choose the FAQ vocab for its source and offer the option to add/change to other vocabs similar to what the D6 version did.

Edit: Testing with multiple categories and multiple questions does not change the problem. but it does point up the CSS issue described below.

boftx’s picture

More info.

Having categories enabled produces the following fatal error when clicking on "Order":
"Fatal error: Call to undefined function taxonomy_term_count_nodes() in /sites/all/modules/faq/faq.admin.inc on line 370"

boftx’s picture

One little styling issue. The div class "<div class="faq-question-answer faq-viewed" style="clear: both;">" needs the clear both property to prevent the next question from bumping up against the category name when using the answer displays under the question inline option, especially with the accordian effect.

That's simple enough to fix in the style sheet, but should be done by the module if possible.

boftx’s picture

With regards to the fatal errors I encountered, I found the following discussion concerning this very issue as a bug report:
Re-add taxonomy_term_count_nodes() (http://drupal.org/node/602240)

In short, unless you want to roll your own your screwed. I am not familiar with the new D7 design philosophy so I can't say what the proper approach to dealing with this (apparently common) problem is.

boftx’s picture

Well, for what it is worth, I dug into making categories work and found a ..... mess.

The short version is that the table taxonomy_term_node does not exist, instead the table taxonomy_index should be used. Worse yet, the vid column does not exist in the new table, so several join conditions failed.

I ripped the missing functions from the D6 Taxonomy module and added them to the bottom of faq.module. The queries had to be converted to the D7 dynamic queries because the call to db_rewrite_sql() no longer exists, either.

Plus, the code "while ($term = db_fetch_object($result)) {" had to be replace by "foreach ($result as $term) {"

Some of you might have gathered by now that PHP is not my native language, I'm a perl programmer by trade specializing in e-commerce, so all of this is very strange to me.

Here is the code that I ripped and changed, other changes were changing the table name and removing the vid conditional. It isn't a total fix, but it clears up a lot of the problem. On the other hand, I am now seeing theme error msgs on occasion. I've gone as far as I going to get tonight.

Hope this helps a little.

/* JGB - Ripped from the D6 taxonomy module since it was removed from D7 */
 
/**
 * Count the number of published nodes classified by a term.
 *
 * @param $tid
 *   The term's ID
 *
 * @param $type
 *   The $node->type. If given, taxonomy_term_count_nodes only counts
 *   nodes of $type that are classified with the term $tid.
 *
 * @return int
 *   An integer representing a number of nodes.
 *   Results are statically cached.
 */
function taxonomy_term_count_nodes($tid, $type = 0) {
  static $count;

  if (!isset($count[$type])) {
    // $type == 0 always evaluates TRUE if $type is a string
    if (is_numeric($type)) {
//      $result = db_query(db_rewrite_sql('SELECT t.tid, COUNT(n.nid) AS c FROM {term_node} t INNER JOIN {node} n ON t.vid = n.vid WHERE n.status = 1 GROUP BY t.tid'));
      // JGB - convert to D7 dynamic queries.
      $tquery = db_select('taxonomy_index','t');
      $n_alias = $tquery->join('node','n','t.nid = n.nid');
      $tquery->fields('t',array('tid'));
      $cnt_alias = $tquery->addExpression('count(n.nid)','c');
      $tquery
        ->condition('n.status',1)
        ->groupBy("t.tid");
      $result = $tquery->execute();
    }
    else {
//      $result = db_query(db_rewrite_sql("SELECT t.tid, COUNT(n.nid) AS c FROM {term_node} t INNER JOIN {node} n ON t.vid = n.vid WHERE n.status = 1 AND n.type = '%s' GROUP BY t.tid"), $type);
      // JGB - convert to D7 dynamic queries.
      $tquery = db_select('taxonomy_index','t');
      $n_alias = $tquery->join('node','n','t.nid = n.nid');
      $tquery->fields('t',array('tid'));
      $cnt_alias = $tquery->addExpression('count(n.nid)','c');
      $tquery
        ->condition("{$n_alias}.status",1)
        ->condition("{$n_alias}.type",$type)
        ->groupBy("t.tid");
      $result = $tquery->execute();
    }
    $count[$type] = array();
//    while ($term = db_fetch_object($result)) {
    foreach ($result as $term) {
      $count[$type][$term->tid] = $term->c;
    }   
  }
  $children_count = 0;
  foreach (_taxonomy_term_children($tid) as $c) {
    $children_count += taxonomy_term_count_nodes($c, $type);
  }
  return $children_count + (isset($count[$type][$tid]) ? $count[$type][$tid] : 0);
}

/**
 * Helper for taxonomy_term_count_nodes(). Used to find out
 * which terms are children of a parent term.
 *
 * @param $tid
 *   The parent term's ID
 *
 * @return array
 *   An array of term IDs representing the children of $tid.
 *   Results are statically cached.
 *
 */
function _taxonomy_term_children($tid) {
  static $children;

  if (!isset($children)) {
    $result = db_query('SELECT tid, parent FROM {taxonomy_term_hierarchy}');
//    while ($term = db_fetch_object($result)) {
    foreach ($result as $term) {
      $children[$term->parent][] = $term->tid;
    }
  }
  return isset($children[$tid]) ? $children[$tid] : array();
}
boftx’s picture

Priority: Normal » Major
Status: Needs review » Needs work

Changing priority and status given the severity and complexity of making categories work correctly. This thread has now gone far beyond the original request and in my opinion should be moved to the 7.x-1.x-dev version.

I should note that I think this is a GREAT module under D6 and I would be hard-pressed to even consider D7 without it. Helping to find fixes to problems like this is the least I can do to say thank you.

stella’s picture

I fixed the naming of the "Edit all FAQ nodes" permission and the call to taxonomy_term_count_nodes(). There is a simple replacement function called faq_taxonomy_term_count_nodes() but unfortunately it doesn't count nodes associated with child terms. A longer term solution will need to be found for this, but for now this will do until the rest of the module stabilises.

Basically, once I created the vocab, I started seeing the following error message with categorze questions disabled but with the vocab included in the config list.
"Notice: Undefined offset: 3 in faq_page() (line 552 of /sites/all/modules/faq/faq.module)."

I haven't been able to reproduce this issue so far, but it's possible that you were using an older snapshot as the taxonomy_term_count_nodes() issue was fixed yesterday but yet still appeared for you. If it's still happening, can you send me the details of your faq config, particularly the admin/config/content/faq/categories page.

However, excluding the FAQ vocab with categorize enabled resulted in no question being listed.  Could this be related to the fact that there is no option to display uncategorized questions such as was present in the D6 version?

That is by design. You would need to disable the "Categorize questions" option in order to see uncategorized questions.

Also, the question appears whether it has been assigned a term or not.

I can't reproduce this issue. If it's still a problem, please provide more details on your faq configuration.

Also, I found it VERY tedious to set up the categories, having had to create a vocab, and then excluding all but that one, and also having to add a custom taxinomy field to the content type. I guess this is a result of changes to the D7 core, but it sucks just the same. This implies that the module should create the Taxinomy vocab with one default term ("General"?) and the CCK field for it already installed in the content type.

Hmmm, it is more hassle in D7. However, I'm not sure that the FAQ module providing a taxonomy vocab field will help as a lot of sites don't want to categorize their faqs.

I would also suggest having the config automatically choose the FAQ vocab for its source and offer the option to add/change to other vocabs similar to what the D6 version did.

Pretty sure the D6 version doesn't do that...

One little styling issue. The div class "<div class="faq-question-answer faq-viewed" style="clear: both;">" needs the clear both property to prevent the next question from bumping up against the category name when using the answer displays under the question inline option, especially with the accordian effect.

I can't reproduce this either. Perhaps provide a screenshot? What theme are you using?

I also fixed some other issues, including a theme function call.

stella’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev
Status: Needs work » Needs review
boftx’s picture

StatusFileSize
new45.89 KB

With regard to this statement:

Hmmm, it is more hassle in D7. However, I'm not sure that the FAQ module providing a taxonomy vocab field will help as a lot of sites don't want to categorize their faqs.

Is there any reason to not provide a default vocab named FAQ? The site admin could then decide whether to use it or not. I don't think it would interfere with non-categorized operation and saves a small headache (and maybe a little confusion) for those who do want to use it. The hassle of creating a CCK field for the FAQ content type can then be dealt with in the documentation if nothing else.

In the meantime, I'll grab the latest snapshot and see what happens. I know that what I did was very ugly.

As for the styling issue, I am using the Danland theme. I am attaching a screenshot of what I saw.

boftx’s picture

The snapshot available at 21:30 PST seems to have fixed the SQL and table name errors I experienced earlier in faq.module.

However, if you click on "Order", select a category, then click on "Search" you will still get the same kind of error relating to the wrong table name, and I presume the missing join column. Here is the error message I received:

PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'nortxcom_drp8.dr_taxonomy_term_node' doesn't exist: SELECT n.nid AS nid, n.title AS title, if((w.weight IS NULL), :default_weight, w.weight) AS weight FROM {node} n INNER JOIN {taxonomy_term_node} tn ON (n.nid = tn.nid AND n.vid = tn.vid) LEFT OUTER JOIN {faq_weights} w ON n.nid = w.nid AND w.tid = :category WHERE (n.type = :db_condition_placeholder_0) AND (n.status = :db_condition_placeholder_1) ORDER BY weight ASC, n.sticky DESC, n.created DESC; Array ( [:db_condition_placeholder_0] => faq [:db_condition_placeholder_1] => 1 [:category] => 3 [:default_weight] => 0 ) in faq_order_settings_form() (line 426 of /sites/all/modules/faq/faq.admin.inc).
boftx’s picture

Regarding this comment:

That is by design. You would need to disable the "Categorize questions" option in order to see uncategorized questions.

I would suggest that any uncategorized questions be shown for users with admin permission in a seperate group.

Granted, in a default install, this could be addressed by making the category tag required in the content type, but I don't know what issues this would present for the faq_ask module (which is a very handy module.) Without something like this, it seems that an admin would not have an easy way to know that there are questions that are not being shown.

I had confused the action of the Weblink module with FAQ in this regard. That module has an option to display uncategorized items in a seperate group named "Uncategorized".

boftx’s picture

Just test the latest build available on 2011-01-11 at 09:45.

Was able to click on Order, then Search without a problem. However, no entries were displayed even though they existed for that category.

When I clicked on the "List" tab I received this error message: (all paths are from the drupal install root.)

•Warning: Illegal offset type in theme() (line 811 of /includes/theme.inc).
•Warning: Illegal offset type in theme() (line 820 of /includes/theme.inc).
•Notice: Undefined index: form in theme_faq_draggable_question_order_table() (line 1640 of /sites/all/modules/faq/faq.module).
•Warning: Invalid argument supplied for foreach() in element_children() (line 6046 of /includes/common.inc).
•Warning: Invalid argument supplied for foreach() in element_children() (line 6046 of /includes/common.inc).
stella’s picture

@boftx - can you try clearing your Drupal cache?

boftx’s picture

Clearing all caches in the admin area cleared both problems. I didn't think to do that since I don't have any cache configured, but it seems there is some going on anyway. Thanks for the tip!

New behaviour observed. After clicking on order, and selecting a category, all questions are displayed no matter what category they are in. Reordering does not take effect when going back to the list view, but does not move the questions out of the assigned category. This was tested with two questions in each of two categories. Testing with just a single question in each category, while displaying the all questions shown bug, does not demonstrate the re-order being ignored problem correctly.

boftx’s picture

Regarding the styling issue previously mentioned, the class tag "clearfix" should be added to any "faq-question-answer" div.

stella’s picture

I can't reproduce the styling problem you've described with the Bartik core theme, so I'm inclined to think that it is a problem with the Danland theme or some other module's css.

I would suggest that any uncategorized questions be shown for users with admin permission in a seperate group.

This would be new functionality (not present in D6 version) and this ticket is purely for the D7 port and so a separate ticket should be opened, though I remain to be convinced.

Granted, in a default install, this could be addressed by making the category tag required in the content type, ...

Not really an option as a lot of users don't want to categorize their faqs.

I've also fixed the ordering of categorised faqs.

boftx’s picture

Even though the styling issue might be a problem with the Danland theme itself (which I haven't had time to test against other themes) the fix is so simple, merely adding the "clearfix" class tag to the div, that I see little reason not to do so.

I understand that part of what I am addressing when it comes to categories is a result of what I would call major changes to the Taxonomy module and Drupal core. Be that as it may, I believe that making things easier for the admin is a Good Thing (tm) overall. That is my main argument in support of showing un-categorized questions for those with admin permissions. This particular functionality is not critical at this point in time, but should not be forgotten.

Edit: I just tested the Kanji and Basic themes and they don't show the styling issue, and I confirmed that Bartik doesn't either. So it would appear that it is a Danland related issue. That said, I would still suggest adding the "clearfix" tag just so that others don't run into the same thing as a defensive measure.

stella’s picture

Even though the styling issue might be a problem with the Danland theme itself (which I haven't had time to test against other themes) the fix is so simple, merely adding the "clearfix" class tag to the div, that I see little reason not to do so.

I won't add theme specific fixes to the module. You should be able to fix it the theme layer though.

boftx’s picture

Ordering problem appears to be fixed. I'll test with other categroy group/question display options to see what happens.

Looking forward to the real release for this module being soon.

boftx’s picture

For those who might run into a mis-behaving theme as I apparently have, here is the fix. I put the following into the theme's local.css file:

.faq-question-answer, .faq-qa-header {
  clear: both;
}

Kudos to stella for having very good (comprehensive) divs and class names to begin with, it makes this kind of customization trivial. I should add that after thinking about it some more I agree that putting any changes like this in a local theme file is the correct solution instead of adding another class tag in the module that depends upon a specific D7 css definition.

bryancasler’s picture

subscribe

pbuyle’s picture

subscribe

pbuyle’s picture

sreynen’s picture

Status: Needs review » Fixed

This issue is now being used as a catch-all for any problem with the D7 port. These problems should each have their own issue so the discussions can remain focused. I'm marking this as "fixed" (we have a D7 port) and suggest remaining problems here be opened as separate issues against the D7 version.

Status: Needs review » Closed (fixed)

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