Posted by mokargas on January 29, 2008 at 11:51pm
Hello all
I have a few user roles (named Editor, Contributor) using my site, and I do not want them to change the filter settings at all from what they are by default. This is on a Drupal 5.6 site.
Is there a way to remove the Input Formats section of a node/add, node/edit form, so users can't touch these settings, but still retain the section for Admin type users? Is there a 'drupal' way to do this, outside css'ing the section to oblivion?
Thanks in advance.
Comments
I "think" that's what the
I "think" that's what the "administer filters" permission option is in "Acecss Control" (/admin/user/access).
Try disabling it for Anonymous users.
Ray Smith
http://RaymondSmith.com
Ray Smith
http://RaymondSmith.com
You need to define which
You need to define which user roles can use which input formats, you'll need Filter Default to do that.
I believe the "Default
I believe the "Default Filter" module only sets the "default" value for the filter. It doesn't stop the user from changing to another option.
The original question was can it be hidden or disabled.
I did a quick test and turning off the "administer filters" option in user access does remove the "Input Format" option when creating content (for the role that was disabled).
Ray Smith
http://RaymondSmith.com
Ray Smith
http://RaymondSmith.com
You're right, but you can
You're right, but you can also set which roles can use each format by configuring the format (site config > Input formats > configure), but when you set a default format it automatically allows all users to use it. The Filter Default module gives you more control to get around this.
I guess there's no need for any extra modules in this case, just change the permissions at Site configuration > Input formats.
Both of your solutions
Both of your solutions together helped me achieve exactly what I wanted.
Thankyou Rowanw and ray_223 :)
I must be missing something.
I must be missing something. Filter Default only allows me to set a default format per role, but does not prevent access to the global default format. The Default Filter module is not a solution to getting rid of the Input Format options and specifically states this in the module:
I need anon users to have Filtered HTML and auth users to have Full HTML without either of them seeing the Input Format option. The Filter Default module solves this. But auth users still have access to the gloabl default format (Filtered HTML) therefore the Filter Options still display in node forms for auth users.
The administer filters permission has no effect on the Input Format options when adding/editing content. I'm not sure if something has changed between 5.6 and 5.7 but I suspect the above statement to be misleading.
Any more ideas?
Okay. I ended up reading a
Okay. I ended up reading a great post by Gabor that lead me to the Filter By Node Type module which allowed me to enable only one input format for each node type and removing the Input Format option from node forms.
What about Formatting Guidelines
Hello,
Thanks for your input on this thread - I too was not able to get there until your post. The Filter By Node Type module *did* remove the "Input format" option as I desired, but kept the Formatting Guidelines. Not much of an improvement in this case, as it's unnecessary, takes up room, and will probably confuse people.
This led me to disable and remove the module altogether. Strangely, though, the effect is still there for that content type: The input format link is gone and the Formatting guidelines area remains. Very strange.
I'm not sure what your experience was along these lines, but I'd be interested to know if you have any thoughts on this!
Thanks,
Jim
Marc
yes thanks this is what i was looking for was this not a default in the older drupal versions
marcj
"administer filters"
"administer filters" at admin/user/access only controls whether the user has access to admin/settings/filters
Granted, it also overrides other format access restrictions, and so i a user "restricted" to a single format is granted "administer filters" privilege, s/he will see ALL formats in "Input Format" fieldset.
However, if you have a user with access to, say, two input formats, unchecking "administer filters" will not make it one or hide "Input format" fieldset.
A>
Question still unanswered...
Thank you for the clarification. I have been over this setup multiple times and believe I have the access control and input formats correctly configured.
It is specifically the "More information about formatting options" link (and description text) that appears below the body field that I can't get rid of. This is showing whether TinyMCE is enabled or not, though the amount of additional information changes....
At admin/settings/filters/1 there is: Formatting guidelines - These are the guidelines that users will see for posting in this input format. They are automatically generated from the filter settings."
It is these Formatting guidelines and the link to more information that I want to remove or hide for users. Does anyone know of a way to do this??
Thanks,
Jim
Question answered
Solution here:
http://drupal.org/node/35122#comment-746238
--
Orvad
--
Orvad
Another solution: use hook_form_alter()
I solved this by using hook_form_alter() and CSS.
This would be ridiculously simple if the fieldsets had IDs or some other easy way to access them with CSS.
You can always add IDs and classes into a form though with hook_form_alter(), fortunately.
Here is the code for Drupal 6:
function MODULENAME_form_alter(&$form, $form_state, $form_id) {switch($form_id){
case 'story_node_form':
$form['body_field']['format']['#attributes']['class'] = 'invisible';
break;
}
}
Then in your stylesheet just add:
.invisible{visibility:hidden;
}
(or display:none, whichever is your preference)
Edit: I am using the filter_default module as well.
Another solution with hook_form_alter
Without using CSS you can essentially achieve the same thing by setting the access to false on the format field. The following will hide the format filter for everyone that doesn't have the administer filters privilege.
<?phpfunction MODULENAME_form_alter(&$form, $form_state, $form_id) {
switch($form_id){
case 'story_node_form':
$form['body_field']['#access'] = user_access('administer filters');
break;
}
}
?>
The Form Defaults module is also a handy module for hiding fields in a form.
Two problems. First you
Two problems. First you mean to do this as you don't want to hide the body field, just the input format fieldset.
$form['body_field']['format']['#access'] = user_access('administer filters');Secondly, you remove the field from the form, not hiding it. So the post form won't take the your default input format value.
You definitely want to hide it, not remove it from the form.
Secondly, you remove the
This is untrue. Form fields that a user does not have access to still maintains their default values even though they are not output to the form.
What if you want this to be
What if you want this to be variable by role?
Can Drupal evaluate that?
Drupal 6 Solution
Hi,
The below snippet worked perfectly for my Drupal 6 website. Add it in trmplate.php file
/** Override filter.module's theme_filter_tips() function to disable tips display.
*/
function YourThemeName_filter_tips($tips, $long = FALSE, $extra = '') {
return '';
}
function YourThemeName_filter_tips_more_info () {
return '';
}
Don't forget to clear the template cache in your site Administer->Site Configuration->Performance->Clear Cached Data otherwise you won't see any change.
P.S. No need to thank me. I got this from here http://drupal.org/node/35122#comment-972608
Imran Khan
Project Manager
New Earth Marketing
Great snippet and you
Great snippet and you deserve a big thanks anyway.
This works better than to do it in hook_form_alter() inside a module with a funky loop to locate the tip message.
Another method...
The following D5.x snippet selects the input format and hides the form element on specific forms. In my case I needed to set the input format and hide the selection field for comments. You can do the same for your forms if you know the form id, etc:
function YOUR_MODULE_form_alter( $form_id, &$form) {
//Uncomment the following to get track down your form id and
// and other form info
//drupal_set_message("Altering " . $form_id .'<pre>'. print_r($form,1).'</pre>');
if( $form_id == 'comment_form') {
//hide input format select for all except administrator
if (!user_access('administer filters')){
YOUR_MODULE_adjust_comment( $form);
}
}
}
function YOUR_MODULE_adjust_comment( &$form) {
//hide the input format radio fields, and set it to input format id of your choice.
// in my case it's 5. To find the input id, go to /admin/settings/filters and
// roll over the filter you want. The id # will be in the url
$form['comment_filter']['format'] = array('#type' => 'hidden', '#value' => 5, );
}
Hope this helps someone. It helped me.
Veneer | Crack-proof Creative
http://www.veneerstudio.com
Civicsolar | Direct Solar Distribution
http://www.civicsolar.com
Thanks for reposting it - it
Thanks for reposting it - it worked great!
Better Formats module
I used the Better Formats module (http://drupal.org/project/better_formats). 6.x only as of this writing.
Among other things, in permissions it includes:
show format selection
show format tips
show more format tips link
But disabling all of those for my anonymous user, I hid all the input format information for anonymous users. You can do this for other user types as well.
It has a fair amount of other functionality. You may want to take a look.
Drupal adventures at:
http://www.GlobalDoctorOptions.com http://www.OnlineCud.com
what is the easiest solution to hide these guidelines on D5
Hi,
This module is not available for drupal 5, so what is the easiest solution to hide these guidelines on D5 ?
Thanks.
Hide Input format for Drupal 6
This can be helpful for someone who would like to disable Input format, Revision information and Authoring information for all users exept admin
Just copy this function to your theme's template.php and change YOUR_THEME_NAME.
function YOUR_THEME_NAME_fieldset($element) {
global $user;
//this if sentence is important! (returns empty string for selected fields)
if((($element['#title'] == 'Input format') || ($element['#title'] == 'Revision information') || ($element['#title'] == 'Authoring information')) && ($user->uid != 1))
return '';
//below this line is original theme_fieldset() part of function
if (!empty($element['#collapsible'])) {
drupal_add_js('misc/collapse.js');
if (!isset($element['#attributes']['class'])) {
$element['#attributes']['class'] = '';
}
$element['#attributes']['class'] .= ' collapsible';
if (!empty($element['#collapsed'])) {
$element['#attributes']['class'] .= ' collapsed';
}
}
return '<fieldset'. drupal_attributes($element['#attributes']) .'>'. ($element['#title'] ? '<legend>'. $element['#title'] .'</legend>' : '') . (isset($element['#description']) && $element['#description'] ? '<div class="description">'. $element['#description'] .'</div>' : '') . (!empty($element['#children']) ? $element['#children'] : '') . (isset($element['#value']) ? $element['#value'] : '') ."</fieldset>\n";
}
Now I only have the fields I need when creating content ;)
Thanks
thank you alesr
It works for me
Thanks a lot.
www.caarcher.biz
Here's my version :)
Here's a snippet that keeps the form fields there but *hides* them, even from the admin user. Useful for clients who don't want to get confused by this stuff. Edit the switch statement to allow fieldsets you *do* need displayed. I'm currently experimenting with hiding all of them to see if I can get away with it. Makes the node/add form much simpler for admins - which is great.
<?php
/** Hide certain fieldsets **/
function YOURTHEME_fieldset($element) {
// remove stuff we don't want shown
switch ($element['#title']) {
case "Input format":
case "Revision information":
case "Authoring information":
case "Menu settings":
case "URL path settings":
case "Publishing options":
$element['#attributes'] = array("style" => "display:none;");
break;
}
if (!empty($element['#collapsible'])) {
drupal_add_js('misc/collapse.js');
if (!isset($element['#attributes']['class'])) {
$element['#attributes']['class'] = '';
}
$element['#attributes']['class'] .= ' collapsible';
if (!empty($element['#collapsed'])) {
$element['#attributes']['class'] .= ' collapsed';
}
}
return '<fieldset'. drupal_attributes($element['#attributes']) .'>'. ($element['#title'] ? '<legend>'. $element['#title'] .'</legend>' : '') . (isset($element['#description']) && $element['#description'] ? '<div class="description">'. $element['#description'] .'</div>' : '') . (!empty($element['#children']) ? $element['#children'] : '') . (isset($element['#value']) ? $element['#value'] : '') ."</fieldset>\n";
}
?>
how do to show without collapse any form fields?
Hello, I am no developer so I am very helpful everything discussed in this issue
Someone could help define a function in template.php if you want some of the form fields eg. Publishing Options , does not appear collapsed, in edit form.-
Thank.
Sorry about my English
Look in the code (switch
Look in the code (switch case) of the last post and remove the options you don't need to hide.
Here is the simple code. You
Here is the simple code. You can make a custom module also using this code. It is work for me.
<?phpfunction comment_custom_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'comment_form') {
foreach ($form['comment_filter']['format'] as $i => $filter) {
if (is_int($i) && !$filter['#type']) {
$form['comment_filter']['format'][$i]['#value'] = '';
$form['comment_filter']['format'] = '';
unset($form['preview']);
unset($form['_author']);
}
}
}
}
?>
My solution (D7)
Hello, first of all, I'm completely novice in Drupal development, but having exactly the same problem and after many tests we have a modified version of text.module that conditionally hides guideliness and format selector and add check for user permission on locked formats. My version replaces radios for combo selection and adds extra checkbox for locking format (hides selector and guideliness). I will be happy if someone can revisited this approach. Using this version requires refresh existing fields (content types/*/edit field), because there are changes in instance attributes.
Thank you for,
add to text.module:
/**
* this method changes the behaviour of the
* filter_process_format, allowing to show
* or hide the format selector
***/
function text_filter_process_format($element)
{
global $user;
// Check if filter_process_format output has detected conflicts
if(isset($element['format']['#access']) && !$element['format']['#access'])
{
//keep it unaltered
return $element;
}
//check some flawors
if(!isset($element['#entity_type']) or !isset($element['#field_name']) or !isset($element['#bundle']))
{
return $element;
}
$instance = field_info_instance($element['#entity_type'],$element['#field_name'],$element['#bundle']);
if(isset($instance['settings']))
{
/**
If user_choice is disabled, we can do the work
**/
if(!$instance['settings']['user_choice'])
{
/**
But previously, we need to check if the user holds permissions for use the locked format
**/
$format = $instance['settings']['text_processing'];
$formats = filter_formats($user);
if(!isset($formats[$format]))
{
//from filters.module ...
// Overload default values into #value to make them unalterable.
$element['value']['#value'] = $element['value']['#default_value'];
$element['format']['format']['#value'] = $element['format']['format']['#default_value'];
// Prepend #pre_render callback to replace field value with user notice
// prior to rendering.
$element['value'] += array('#pre_render' => array());
array_unshift($element['value']['#pre_render'], 'filter_form_access_denied');
// Cosmetic adjustments.
if (isset($element['value']['#rows'])) {
$element['value']['#rows'] = 3;
}
$element['value']['#disabled'] = TRUE;
$element['value']['#resizable'] = FALSE;
// Hide the text format selector and any other child element (such as text
// field's summary).
foreach (element_children($element) as $key) {
if ($key != 'value') {
$element[$key]['#access'] = FALSE;
}
}
return $element;
}
$element['format']['format']['#default_value']= $format;
$element['#format']= $format;
$element['#attributes']['#format']= $format;
//Remove all other formats
$options = $element['format']['format']['#options'];
$element['format']['format']['#options'] = array($element['#format'] => $options[$format]);
$element['format']['format']['#access'] = false;
$element['format']['#type'] = 'container';
unset($element['format']['help']);
unset($element['format']['guidelines']);
}
}
return $element;
}
replace hook_field_info:
function text_field_info() {return array(
'text' => array(
'label' => t('Text'),
'description' => t('This field stores varchar text in the database.'),
'settings' => array('max_length' => 255),
'instance_settings' => array('text_processing' => 'plain_text','user_choice' => 0),
'default_widget' => 'text_textfield',
'default_formatter' => 'text_default',
),
'text_long' => array(
'label' => t('Long text'),
'description' => t('This field stores long text in the database.'),
'instance_settings' => array('text_processing' => 'plain_text','user_choice' => 1),
'default_widget' => 'text_textarea',
'default_formatter' => 'text_default',
),
'text_with_summary' => array(
'label' => t('Long text and summary'),
'description' => t('This field stores long text in the database along with optional summary text.'),
'instance_settings' => array('text_processing' => 'plain_text', 'user_choice' => 1,'display_summary' => 0),
'default_widget' => 'text_textarea_with_summary',
'default_formatter' => 'text_default',
),
);
}
replace hook_field_instance_settings_form:
function text_field_instance_settings_form($field, $instance) {
$settings = $instance['settings'];
/**
For unfiltered text types we skip any kind of modification
**/
if($field['type']!='text')
{
/**
Create a selector for the format
so we can choose the format even when
no default value is defined
**/
$formats = array_reverse(filter_formats());
$format_idx = array();
foreach($formats as $format => $obj){
$format_idx[$obj->format] = $obj->name;
}
$form['text_processing'] = array(
'#type' => 'select',
'#title' => t('Text format'),
'#options' => $format_idx,
'#default_value' => $settings['text_processing'],
'#access' => count($format_idx) > 1,
'#attributes' => array('class' => array('filter-list')),
);
/**
Add ability for indicate user freedom of filter change or not
**/
$form['user_choice'] = array(
'#type' => 'checkbox',
'#title' => t('User selects input format'),
'#default_value' => count($format_idx) > 1? $settings['user_choice']:0,
'#access' => count($format_idx) > 1,
'#weight' => 0,
);
}
if ($field['type'] == 'text_with_summary') {
$form['display_summary'] = array(
'#type' => 'checkbox',
'#title' => t('Summary input'),
'#default_value' => $settings['display_summary'],
'#description' => t('This allows authors to input an explicit summary, to be displayed instead of the automatically trimmed text when using the "Summary or trimmed" display type.'),
);
}
return $form;
}
replace hook_field_load:
function text_field_load($entity_type, $entities, $field, $instances, $langcode, &$items) {foreach ($entities as $id => $entity) {
foreach ($items[$id] as $delta => $item) {
// Only process items with a cacheable format, the rest will be handled
// by formatters if needed.
if (($instances[$id]['settings']['text_processing']=='plain_text' &&
!$instances[$id]['settings']['user_choice'] ) || filter_format_allowcache($item['format'])) {
$items[$id][$delta]['safe_value'] = isset($item['value']) ? _text_sanitize($instances[$id], $langcode, $item, 'value') : '';
if ($field['type'] == 'text_with_summary') {
$items[$id][$delta]['safe_summary'] = isset($item['summary']) ? _text_sanitize($instances[$id], $langcode, $item, 'summary') : '';
}
}
}
}
}
replace hook_view_formatter_view:
function text_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
$element = array();
switch ($display['type']) {
case 'text_default':
case 'text_trimmed':
foreach ($items as $delta => $item) {
$output = _text_sanitize($instance, $langcode, $item, 'value');
if ($display['type'] == 'text_trimmed') {
if($instance['settings']['text_processing'] == 'plain_text' && !$instance['settings']['user_choice']) {
$output = text_summary($output, NULL, $display['settings']['trim_length']);
}
else {
$output = text_summary($output, $item['format'], $display['settings']['trim_length']);
}
}
$element[$delta] = array('#markup' => $output);
}
break;
case 'text_summary_or_trimmed':
foreach ($items as $delta => $item) {
if (!empty($item['summary'])) {
$output = _text_sanitize($instance, $langcode, $item, 'summary');
}
else {
$output = _text_sanitize($instance, $langcode, $item, 'value');
if($instance['settings']['text_processing'] == 'plain_text' && !$instance['settings']['user_choice']) {
$output = text_summary($output, NULL, $display['settings']['trim_length']);
}
else {
$output = text_summary($output, $item['format'] , $display['settings']['trim_length']);
}
}
$element[$delta] = array('#markup' => $output);
}
break;
case 'text_plain':
foreach ($items as $delta => $item) {
$element[$delta] = array('#markup' => strip_tags($item['value']));
}
break;
}
return $element;
}
replace _text_sanitize:
function _text_sanitize($instance, $langcode, $item, $column) {// If the value uses a cacheable text format, text_field_load() precomputes
// the sanitized string.
if (isset($item["safe_$column"])) {
return $item["safe_$column"];
}
if($instance['settings']['text_processing'] == 'plain_text' && !$instance['settings']['user_choice']) {
return check_plain($item[$column]);
}
else {
return check_markup($item[$column], $item['format'], $langcode);
}
}
replace hook_view_widget_form:
function text_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
$summary_widget = array();
$main_widget = array();
switch ($instance['widget']['type']) {
case 'text_textfield':
$main_widget = $element + array(
'#type' => 'textfield',
'#default_value' => isset($items[$delta]['value']) ? $items[$delta]['value'] : NULL,
'#size' => $instance['widget']['settings']['size'],
'#maxlength' => $field['settings']['max_length'],
'#attributes' => array('class' => array('text-full')),
);
break;
case 'text_textarea_with_summary':
$display = !empty($items[$delta]['summary']) || !empty($instance['settings']['display_summary']);
$summary_widget = array(
'#type' => $display ? 'textarea' : 'value',
'#default_value' => isset($items[$delta]['summary']) ? $items[$delta]['summary'] : NULL,
'#title' => t('Summary'),
'#rows' => $instance['widget']['settings']['summary_rows'],
'#description' => t('Leave blank to use trimmed value of full text as the summary.'),
'#attached' => array(
'js' => array(drupal_get_path('module', 'text') . '/text.js'),
),
'#attributes' => array('class' => array('text-summary')),
'#prefix' => '<div class="text-summary-wrapper">',
'#suffix' => '</div>',
'#weight' => -10,
);
// Fall through to the next case.
case 'text_textarea':
$main_widget = $element + array(
'#type' => 'textarea',
'#default_value' => isset($items[$delta]['value']) ? $items[$delta]['value'] : NULL,
'#rows' => $instance['widget']['settings']['rows'],
'#attributes' => array('class' => array('text-full')),
);
break;
}
if ($main_widget) {
// Conditionally alter the form element's type if text processing is enabled.
if ($instance['settings']['text_processing']!= 'plain_text') {
$element = $main_widget;
$element['#type'] = 'text_format';
if(isset($items[$delta]['format']))
{
$element['#format'] = $items[$delta]['format'];
}
elseif(isset($instance['settings']['text_processing']))
{
$element['#format'] = $instance['settings']['text_processing'];
}
$element['#base_type'] = $main_widget['#type'];
}
else {
$element['value'] = $main_widget;
}
}
if ($summary_widget) {
$element['summary'] = $summary_widget;
}
return $element;
}
Mel Viso.