I've found it useful to have swf replacement disabled when i'm editing and adding nodes - this makes it easier to stay in the admin section and work as a moderator for the site. I've modified the module as below to do this - if anyone finds this useful then perhaps it could be good to stick it in the module.

Added a tickbox and variable in this function - swfaddress_admin_form():

  $form['swfaddress_admin_disable'] = array(
    '#type' => 'checkbox',
    '#title' => t('Disable if logged in as a node administrator'),
    '#description' => t('If checked this will turn off Flash replacement if logged in with administer node permissions'),
    '#default_value' => variable_get('swfaddress_admin_disable', FALSE)
  );

Changed the logic in this function - swfaddress_init() where the javascript gets added:

  // Converted from the old hook_menu($may_cache) by chok.
  //&& (variable_get('swfaddress_replacement_enabled', FALSE) && !user_access('administer nodes'))
  if (variable_get('swfaddress_replacement_enabled', FALSE)
    && variable_get('clean_url', 0) == 1
    && _swfaddress_path_permitted()

    // I've added the line below...
	&& (!variable_get('swfaddress_admin_disable', FALSE) || !user_access('administer nodes'))

    ) {
    // It is vitally important that swfobject.js be included before SWFAddress!
CommentFileSizeAuthor
#3 swfaddress_1.patch2.66 KBidflood
#2 swfaddress.patch2.73 KBidflood

Comments

mllr’s picture

Great improvement of usability! Thanks, I’ve been looking exactly for this :-)

idflood’s picture

StatusFileSize
new2.73 KB

I'm wondering if it would be better to add a new permission "swfaddress enabled". It would give the ability to enable/disable swfaddress by role. I also added the setting provided above, but made it only affect user 1 ( the super admin ).

add the option to disable replacement for user 1 in swfaddress_admin_form():

<?php
  $form['swfaddress_admin_disable'] = array(
    '#type' => 'checkbox',
    '#title' => t('Disable if logged in as superuser'),
    '#description' => t('If checked this will turn off Flash replacement if logged as superuser'),
    '#default_value' => variable_get('swfaddress_admin_disable', FALSE)
  );
?>

add the new permission:

<?php
function swfaddress_perm() {
  $permissions = array(
    'administer swfaddress',
    'swfaddress enabled'
  );
  return $permissions;
}
?>

get the global user variable and check the option, the user and the permission before adding the javascripts.

<?php
function swfaddress_init() {
  $base = _swfaddress_base_path();
  $path = $_SERVER['QUERY_STRING'];
  global $user;

...

  // Converted from the old hook_menu($may_cache) by chok.
  if (variable_get('swfaddress_replacement_enabled', FALSE)
    && variable_get('clean_url', 0) == 1
    && _swfaddress_path_permitted()
    && user_access('swfaddress enabled')
    && ($user->uid != 1 || !variable_get('swfaddress_admin_disable', FALSE))) {
    // It is vitally important that swfobject.js be included before SWFAddress!
?>
idflood’s picture

StatusFileSize
new2.66 KB

forgot to remove unneeded stuff from the patch file. Here is the corrected version