Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
drupal.org
better_formats
Commits
2aecb113
Commit
2aecb113
authored
Dec 09, 2008
by
dragonwize
Browse files
fixed bug with non-allowed formats per node type showing on existing entries
parent
3fdd7f62
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
15 deletions
+9
-15
better_formats.module
better_formats.module
+9
-15
No files found.
better_formats.module
View file @
2aecb113
...
...
@@ -257,7 +257,7 @@ function better_formats_textarea_process($element, $edit, $form_state, $form) {
// set default format for cck textarea
$element
[
'#value'
][
$filter_key
]
=
$format
;
// set filter selection form
$element
[
$filter_key
]
=
better_formats_filter_form
(
$format
,
1
,
$parents
);
$element
[
$filter_key
]
=
better_formats_filter_form
(
$format
,
$form
[
'type'
][
'#value'
],
1
,
$parents
);
}
return
$element
;
...
...
@@ -274,22 +274,23 @@ function better_formats_set_node_format(&$form) {
$format
=
better_formats_get_current_format
(
$form
[
'body_field'
][
'format'
]);
}
// overwrite the filter form with our own
$form
[
'body_field'
][
'format'
]
=
better_formats_filter_form
(
$format
);
$form
[
'body_field'
][
'format'
]
=
better_formats_filter_form
(
$format
,
$form
[
'type'
][
'#value'
]
);
}
}
function
better_formats_set_comment_format
(
&
$form
)
{
if
(
isset
(
$form
[
'comment_filter'
][
'format'
]))
{
$node
=
node_load
(
$form
[
'nid'
][
'#value'
]);
// only get default for new entries
if
(
empty
(
$form
[
'cid'
][
'#value'
]))
{
$node
=
node_load
(
$form
[
'nid'
][
'#value'
]);
$format
=
better_formats_get_default_format
(
'comment'
,
$node
->
type
);
}
else
{
// get existing format for comment
$format
=
better_formats_get_current_format
(
$form
[
'comment_filter'
][
'format'
]);
}
// overwrite the filter form with our own
$form
[
'comment_filter'
][
'format'
]
=
better_formats_filter_form
(
$format
);
$form
[
'comment_filter'
][
'format'
]
=
better_formats_filter_form
(
$format
,
$node
->
type
);
}
}
...
...
@@ -313,10 +314,6 @@ function better_formats_get_current_format($form) {
function
better_formats_get_default_format
(
$mode
,
$node_type
=
''
)
{
static
$format
;
// putting node type into the global space to be used by the per node type
// allowed formats feature in better_formats_filter_form()
$GLOBALS
[
'better_formats_node_type'
]
=
$node_type
;
// default our type to the mode (node or comment)
$type
=
$mode
;
...
...
@@ -360,25 +357,22 @@ function better_formats_get_default_format($mode, $node_type = '') {
* @param
* @return array FAPI array for the format of a textarea
*/
function
better_formats_filter_form
(
$value
=
FILTER_FORMAT_DEFAULT
,
$weight
=
1
,
$parents
=
array
(
'format'
))
{
global
$better_formats_node_type
;
$node_type
=
$better_formats_node_type
;
function
better_formats_filter_form
(
$value
=
FILTER_FORMAT_DEFAULT
,
$node_type
=
''
,
$weight
=
1
,
$parents
=
array
(
'format'
))
{
$value
=
filter_resolve_format
(
$value
);
$formats
=
filter_formats
();
// check if there are node type restrictions on allowed formats
// if there are no retrictions set we use the site globals as default
$per_node_type
=
variable_get
(
'better_formats_per_node_type'
,
FALSE
);
$allowed_formats
=
variable_get
(
'better_formats_allowed_'
.
$node_type
,
false
);
if
(
$allowed_formats
)
{
if
(
$per_node_type
&&
$allowed_formats
)
{
foreach
(
$formats
as
$key
=>
$format
)
{
if
(
!
in_array
(
$format
->
format
,
$allowed_formats
))
{
unset
(
$formats
[
$key
]);
}
}
}
// extra check to ensure default format is available to the user
// else we fall back to the site default format
$default
=
isset
(
$formats
[
$value
])
?
$formats
[
$value
]
->
format
:
filter_resolve_format
(
FILTER_FORMAT_DEFAULT
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment