Closed olafgrabienski closed 3 months ago
You are right that the Definition list behaves like Accordion. If you read from line 447 on Drupal 7 version of the module then you will notice the accordion tied up to faqfield_definition_list
:
/*
* This formatter displays the FAQ content as definition list, and has been
* updated with the addition of accordion functionality.
*
* Taken from the Web Accessibility for Developers course offered by
* The Chang School at Ryerson University, for details see:
* https://www.canvas.net/browse/ryersonu/courses/adv-web-accessibility
*/
case 'faqfield_definition_list':
drupal_add_js(
drupal_get_path('module', 'faqfield') . '/js/faqfield.accordion_dl.js',
array(
'scope' => 'header',
'weight' => 51,
)
);
drupal_add_css(
drupal_get_path('module', 'faqfield') . '/css/faqfield.accordion_dl.css'
);
On the other hand, the faqfield_accordion
formatted that looked like:
case 'faqfield_accordion':
// Generate faqfield id by fieldname and entity id.
$entity_ids = entity_extract_ids($entity_type, $entity);
$faqfield_id = 'faqfield_' . $field['field_name'] . '_' . $entity_ids[0];
// We need to convert the element active value to an integer for jQuery.
if ($display['settings']['active'] !== '') {
settype($display['settings']['active'], 'int');
}
// If setting was left blank, we set FALSE so no element will be active.
else {
$display['settings']['active'] = FALSE;
}
// If jquery_update module is installed and a version >1.5 is used
// the "autoHeight" option has been replaced with "heightStyle".
// To be compatible to higher jQuery versions we have to switch accordingly.
if (module_exists('jquery_update') && variable_get('jquery_update_jquery_version') !== '1.5') {
if ($display['settings']['autoHeight']) {
$display['settings']['heightStyle'] = 'auto';
}
else {
$display['settings']['heightStyle'] = 'content';
}
unset($display['settings']['autoHeight']);
}
// Attach accordion JS library and related display settings.
$element[0]['#attached']['library'][] = array('faqfield', 'accordion');
$element[0]['#attached']['js'][] = array(
'type' => 'setting',
'data' => array('faqfield' => array('#' . $faqfield_id => $display['settings'])),
);
// We need to put all of this within a single piece of markup,
// otherwise this would not work with jQuery accordion.
$element[0]['#markup'] = '<div id="' . $faqfield_id . '">';
foreach ($items as $key => $item) {
// Decide whether to use the default format or the custom one.
$format = (!empty($item['answer_format']) ? $item['answer_format'] : $field['settings']['format']);
// Build the markup.
$name = 'faq-' . str_replace(' ', '-', $item['question']);
// Store the raw anchor name so the accordion item can be unfurled.
$anchors[$name] = $key;
$name = check_plain($name);
$element[0]['#markup'] .= '<h3 class="faqfield-question" id="' . $name . '"><a href="#' . $name . '">' . check_plain($item['question']) . '</a></h3>';
$element[0]['#markup'] .= '<div class="faqfield-answer">' . check_markup($item['answer'], $format) . '</div>';
}
$element[0]['#markup'] .= '</div>';
$element[0]['#attached']['js'][] = array(
'type' => 'setting',
'data' => array('faqfieldAnchors' => $anchors),
);
break;
didn't want to work, so it was decided to just remove non-functional part of the code. If someone has time to tackle this problem and get the removed code back into the module, I don't mind accepting PRs.
For now, I'll go ahead and rename the Definition list to Accordion to avoid possible confusions in the future.
I'm testing this module which looks very useful. In the display settings, I can't find the Accordion.
The README mentions the following formats:
<dl>
FAQ format)Actually, the Definition list behaves like an Accordion. Now I'm wondering, if the 'original' Accordion is missing or if it was merged with the Definition list.