updated webform & faq

This commit is contained in:
2020-03-27 14:25:57 +01:00
parent 1e27fcca51
commit be549a75f6
35 changed files with 569 additions and 239 deletions

View File

@@ -74,7 +74,7 @@ function faq_node_access($node, $op, $account = NULL) {
*/
function faq_menu() {
$items = array();
$faq_path = variable_get('faq_path', 'faq-page');
$faq_path = _faq_path();
$items[$faq_path] = array(
'title' => 'Frequently Asked Questions',
@@ -239,13 +239,13 @@ function faq_form_faq_general_settings_form_alter(&$form, &$form_state) {
*/
function faq_insert($node) {
$items = field_get_items('node', $node, 'field_detailed_question');
$detailed_question = reset($items);
$detailed_question = !empty($items) ? $items[0]['value'] : '';
db_insert('faq_questions')
->fields(array(
'nid' => $node->nid,
'vid' => $node->vid,
'question' => $node->title,
'detailed_question' => $detailed_question['value'],
'detailed_question' => $detailed_question,
))
->execute();
}
@@ -416,6 +416,8 @@ function faq_page($tid = 0, $faq_display = '', $category_display = '') {
module_load_include('inc', 'pathauto');
}
$faqpath = _faq_path();
// Things to provide translations for.
$default_values = array(
t('Frequently Asked Questions'),
@@ -426,7 +428,7 @@ function faq_page($tid = 0, $faq_display = '', $category_display = '') {
$output = $output_answers = '';
drupal_add_css(drupal_get_path('module', 'faq') . '/faq.css');
if (arg(0) == 'faq-page') {
if (arg(0) == $faqpath) {
drupal_set_title(t(variable_get('faq_title', 'Frequently Asked Questions')));
}
if (!module_exists("taxonomy")) {
@@ -441,7 +443,7 @@ function faq_page($tid = 0, $faq_display = '', $category_display = '') {
drupal_goto($alias['alias']);
}
}
if (drupal_match_path($_GET['q'], 'faq-page/*')) {
if (drupal_match_path($_GET['q'], $faqpath . '/*')) {
faq_set_breadcrumb($current_term);
}
}
@@ -571,7 +573,7 @@ function faq_page($tid = 0, $faq_display = '', $category_display = '') {
}
$valid_vocab = TRUE;
if ($category_display == "new_page") {
if ($category_display == 'new_page') {
$vocab_items = _get_indented_faq_terms($vid, 0);
$items = array_merge($items, $vocab_items);
}
@@ -616,16 +618,22 @@ function faq_page($tid = 0, $faq_display = '', $category_display = '') {
}
}
$faq_description = t(variable_get('faq_description', ''));
$format = variable_get('faq_description_format', 0);
$faq_description_default = array('value' => '', 'format' => filter_fallback_format());
$faq_description = variable_get('faq_description', $faq_description_default);
$format = $faq_description['format'];
if ($format) {
$faq_description = check_markup($faq_description, $format);
$description = check_markup($faq_description['value'], $format);
}
else {
$description = check_plain($faq_description['value']);
}
return theme('faq_page',
array(
'content' => $output,
'answers' => $output_answers,
'description' => $faq_description,
'description' => $description,
)
);
}
@@ -943,7 +951,7 @@ function faq_block_view($delta) {
$block['subject'] = t('FAQ Categories');
$items = array();
foreach ($terms as $name => $tid) {
$items[] = l(faq_tt("taxonomy:term:$tid:name", $name), 'faq-page/' . $tid);
$items[] = l(faq_tt("taxonomy:term:$tid:name", $name), _faq_path() . '/' . $tid);
}
$list_style = variable_get('faq_category_listing', 'ul');
$block['content'] = theme('item_list',
@@ -1015,7 +1023,7 @@ function _get_indented_faq_terms($vid, $tid) {
->fetchField();
if ($term_node_count > 0) {
$path = "faq-page/$term->tid";
$path = _faq_path() . "/$term->tid";
if (!drupal_lookup_path('alias', arg(0) . '/' . $term->tid) && module_exists('pathauto')) {
$alias = pathauto_create_alias('faq', 'insert', arg(0) . '/' . $term->tid, array('term' => $term));
@@ -1134,7 +1142,7 @@ function faq_get_faq_list() {
foreach ($nodes as $node) {
if (node_access('view', $node)) {
$items[] = l($node->question, "node/$node->nid");
$items[] = l($node->title, "node/$node->nid");
}
}
@@ -1217,7 +1225,7 @@ function faq_view_question(&$data, $node, $path = NULL, $anchor = NULL) {
}
// Get the detailed question.
$detailed_question = '';
$detailed_question = array();
if ($dq = field_get_items('node', $node, 'field_detailed_question')) {
$detailed_question = reset($dq);
}
@@ -1225,7 +1233,7 @@ function faq_view_question(&$data, $node, $path = NULL, $anchor = NULL) {
if (variable_get('faq_display', 'questions_top') != 'hide_answer'
&& !empty($detailed_question['value'])
&& variable_get('faq_question_length', 'short') == 'both') {
$question .= '<div class="faq-detailed-question">' . $detailed_question['safe_value'] . '</div>';
$question .= '<div class="faq-detailed-question">' . $detailed_question['value'] . '</div>';
}
$data['question'] = $question;
}
@@ -1461,7 +1469,7 @@ function faq_view_child_category_headers($term) {
$term_image = taxonomy_image_display($child_term->tid, array('class' => 'faq-tax-image'));
}
$term_vars['link'] = l(faq_tt("taxonomy:term:$child_term->tid:name", $child_term->name), "faq-page/$child_term->tid");
$term_vars['link'] = l(faq_tt("taxonomy:term:$child_term->tid:name", $child_term->name), _faq_path() . "/$child_term->tid");
$term_vars['description'] = check_markup(faq_tt("taxonomy:term:$child_term->tid:description", $child_term->description));
$term_vars['count'] = $term_node_count;
$term_vars['term_image'] = $term_image;
@@ -1482,7 +1490,7 @@ function faq_pathauto($op) {
$settings['module'] = 'faq';
$settings['groupheader'] = t('FAQ category page settings');
$settings['patterndescr'] = t('Default path pattern (applies to all FAQ categories with blank patterns below)');
$settings['patterndefault'] = t('faq-page/[term:tid]');
$settings['patterndefault'] = t(_faq_path() . '/[term:tid]');
$settings['batch_update_callback'] = 'faq_pathauto_bulkupdate';
$settings['token_type'] = 'term';
return (object) $settings;
@@ -1496,7 +1504,7 @@ function faq_pathauto($op) {
* Implements hook_path_alias_types().
*/
function faq_path_alias_types() {
$objects['faq-page/'] = t('FAQ pages');
$objects[_faq_path() . '/'] = t('FAQ pages');
return $objects;
}
@@ -1511,6 +1519,7 @@ function faq_pathauto_bulkupdate() {
$context['sandbox']['current'] = 0;
}
$faq_path = _faq_path();
// Get the allowed vocabs.
$vocabularies = taxonomy_get_vocabularies('faq');
$vocab_omit = variable_get('faq_omit_vocabulary', array());
@@ -1524,7 +1533,7 @@ function faq_pathauto_bulkupdate() {
// Get tids that need aliasing.
$query = db_select('taxonomy_term_data', 'td');
$query->leftJoin('url_alias', 'ua', "CONCAT('faq-page/', td.tid) = ua.source");
$query->leftJoin('url_alias', 'ua', "CONCAT($faq_path . '/', td.tid) = ua.source");
$query->addField('td', 'tid');
$query->isNull('ua.source');
$query->condition('td.tid', $context['sandbox']['current'], '>');
@@ -1549,7 +1558,7 @@ function faq_pathauto_bulkupdate() {
$terms = taxonomy_term_load_multiple($tids);
foreach ($terms as $term) {
pathauto_create_alias('faq', 'bulkupdate', 'faq-page/' . $term->tid, array('term' => $term));
pathauto_create_alias('faq', 'bulkupdate', $faq_path . '/' . $term->tid, array('term' => $term));
}
$context['sandbox']['count'] += count($tids);
$context['sandbox']['current'] = max($tids);
@@ -1573,7 +1582,7 @@ function faq_taxonomy_term_insert($term) {
if ((isset($vocab_omit[$vid]) && $vocab_omit[$vid] != 0) || ($term->vid != $vid)) {
continue;
}
$alias = pathauto_create_alias('faq', 'insert', 'faq-page/' . $term->tid, array('term' => $term));
$alias = pathauto_create_alias('faq', 'insert', _faq_path() . '/' . $term->tid, array('term' => $term));
}
}
}
@@ -1591,7 +1600,7 @@ function faq_taxonomy_term_update($term) {
if ((isset($vocab_omit[$vid]) && $vocab_omit[$vid] != 0) || ($term->vid != $vid)) {
continue;
}
$alias = pathauto_create_alias('faq', 'update', 'faq-page/' . $term->tid, array('term' => $term));
$alias = pathauto_create_alias('faq', 'update', _faq_path() . '/' . $term->tid, array('term' => $term));
}
}
}
@@ -1602,7 +1611,7 @@ function faq_taxonomy_term_update($term) {
function faq_taxonomy_term_delete($term) {
if (module_exists('pathauto')) {
module_load_include('inc', 'pathauto');
pathauto_path_delete_all("faq-page/{$term->tid}");
pathauto_path_delete_all(_faq_path() . "/{$term->tid}");
}
}
@@ -1617,15 +1626,16 @@ function faq_taxonomy_term_delete($term) {
*/
function faq_set_breadcrumb($term = NULL) {
$breadcrumb = array();
$faq_path = _faq_path();
if (variable_get('faq_custom_breadcrumbs', TRUE)) {
if (module_exists("taxonomy") && $term) {
$breadcrumb[] = l(faq_tt("taxonomy:term:$term->tid:name", $term->name), 'faq-page/' . $term->tid);
$breadcrumb[] = l(faq_tt("taxonomy:term:$term->tid:name", $term->name), $faq_path . '/' . $term->tid);
while ($parents = taxonomy_get_parents($term->tid)) {
$term = array_shift($parents);
$breadcrumb[] = l(faq_tt("taxonomy:term:$term->tid:name", $term->name), 'faq-page/' . $term->tid);
$breadcrumb[] = l(faq_tt("taxonomy:term:$term->tid:name", $term->name), $faq_path . '/' . $term->tid);
}
}
$breadcrumb[] = l(t(variable_get('faq_title', 'Frequently Asked Questions')), 'faq-page');
$breadcrumb[] = l(t(variable_get('faq_title', 'Frequently Asked Questions')), $faq_path);
$breadcrumb[] = l(t('Home'), NULL, array('attributes' => array('title' => variable_get('site_name', ''))));
$breadcrumb = array_reverse($breadcrumb);
return drupal_set_breadcrumb($breadcrumb);
@@ -1815,7 +1825,7 @@ function theme_field_detailed_question($variables) {
}
// Render the items.
$output .= '<div class="faq-detailed-question">' . $variables['safe_value'] . '</div>';
$output .= '<div class="faq-detailed-question">' . $variables['value'] . '</div>';
// Render the top-level DIV.
if (isset($variables['classes']) && isset($variables['attributes'])) {
@@ -1856,3 +1866,10 @@ function theme_faq_draggable_question_order_table($variables) {
$output .= drupal_render_children($form);
return $output;
}
/**
* Helper to get the path for the faq page.
*/
function _faq_path() {
return variable_get('faq_path', 'faq-page');
}