Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
faqfield-3363806
Manage
Activity
Members
Labels
Plan
Custom issue tracker
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Issue forks
faqfield-3363806
Commits
69af0c4e
Commit
69af0c4e
authored
13 years ago
by
Patrick Drotleff
Browse files
Options
Downloads
Patches
Plain Diff
made simple text formatter really themeable
parent
2f8a3222
No related branches found
Branches containing commit
Tags
7.x-1.0-beta2
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
faqfield.module
+39
-7
39 additions, 7 deletions
faqfield.module
with
39 additions
and
7 deletions
faqfield.module
+
39
−
7
View file @
69af0c4e
...
...
@@ -122,7 +122,7 @@ function faqfield_field_formatter_settings_form($field, $instance, $view_mode, $
'#type'
=>
'textfield'
,
'#title'
=>
t
(
'Active'
),
'#default_value'
=>
$settings
[
'active'
],
'#description'
=>
t
(
'
A
ctive element. Leave empty to display none at start.'
),
'#description'
=>
t
(
'
Index of a
ctive element. Leave empty to display none at start.'
),
// @TODO _element_validate_number() is deprecated since 7.8.
// Need (?) to switch to element_validate_number() when most people updated.
//'#element_validate' => array('element_validate_number'),
...
...
@@ -195,12 +195,16 @@ function faqfield_field_formatter_view($entity_type, $entity, $field, $instance,
$element
=
array
();
$format
=
@
$field
[
'settings'
][
'format'
];
$faqfield_id
=
'faqfield_'
.
$field
[
'field_name'
];
switch
(
$display
[
'type'
])
{
// This formatter adds jQuery accordion widget.
// This will not be themeable, because changes would break
// jQuery UI accordion functionality!
case
'faqfield_accordion'
:
$faqfield_id
=
'faqfield_'
.
$field
[
'field_name'
];
// Add jQuery UI accordion library.
drupal_add_library
(
'system'
,
'ui.accordion'
);
drupal_add_js
(
'jQuery(function(){jQuery("#'
.
$faqfield_id
.
'").accordion(Drupal.settings.'
.
$faqfield_id
.
');});'
,
'inline'
);
...
...
@@ -225,20 +229,48 @@ function faqfield_field_formatter_view($entity_type, $entity, $field, $instance,
$element
[
0
][
'#markup'
]
.
=
'</div>'
;
break
;
// This formatter displays the FAQ content as simple text.
// This
themeable
formatter displays the FAQ content as simple text.
case
'faqfield_simple_text'
:
$element
[
'#prefix'
]
=
'<div id="'
.
$faqfield_id
.
'">'
;
foreach
(
$items
as
$delta
=>
$item
)
{
$element
[
$delta
][
'#markup'
]
.
=
'<h3 class="faqfield-question">'
.
check_markup
(
$item
[
'question'
],
$format
)
.
'</h3>'
;
$element
[
$delta
][
'#markup'
]
.
=
'<div class="faqfield-answer">'
.
check_markup
(
$item
[
'answer'
],
$format
)
.
'</div>'
;
$element
[
$delta
]
=
array
(
'#theme'
=>
'faqfield_formatter'
,
// Filter values before passing them to the template.
'#question'
=>
check_markup
(
$item
[
'question'
],
$format
),
'#answer'
=>
check_markup
(
$item
[
'answer'
],
$format
),
);
}
$element
[
'#suffix'
]
.
=
'</div>'
;
break
;
}
return
$element
;
}
/**
* Implements hook_theme().
*/
function
faqfield_theme
()
{
// Themeable simple text formatter.
return
array
(
'faqfield_formatter'
=>
array
(
'variables'
=>
array
(
'question'
=>
NULL
,
'answer'
=>
NULL
),
),
);
}
/**
* Returns HTML for a faqfield formatter.
*
* @param $variables
* An associative array containing:
* - question
* - answer
*/
function
theme_faqfield_formatter
(
$variables
)
{
$output
=
'<h3 class="faqfield-question">'
.
$variables
[
'question'
]
.
'</h3>'
;
$output
.
=
'<div class="faqfield-answer">'
.
$variables
[
'answer'
]
.
'</div>'
;
return
$output
;
}
/**
* Implements hook_field_widget_info().
*/
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment