Hi,

I don't want my members to be able to change any settings in the "gallery settings" fieldset.

I just want to be able to set the defaults and hide the fieldset altogether.

Also, the same with the "blocks" tab at the bottom of the edit/create node page. I would just like to hide this altogether.

Is this possible? I have played around with css, unlcoked all the fields in the db etc but still cannot hide the actual fieldset. All fields within the fieldset disappear but the actual wrapper stays there at full height.

By the by, this should be simpler than hacking the SQL to unlock the fields and set defaults/hide from users.

Any ideas on how to hide?

Thanks.

Shaun

Comments

David_Rothstein’s picture

CSS is OK for hiding something from easy view, but not for actually preventing people from changing it, so it's probably not the best solution anyway.

Have you tried writing a small bit of custom code that uses hook_form_alter() to set '#access' => FALSE on the fieldset?

dRaz’s picture

David,

Thanks for the reply.

I did want to try that solution but I could not find the right .inc file to insert the code....it all seems very "all over the place"? Or maybe I can't see the forest for the trees....

bschilt’s picture

I'm dealing with the same issue. I want to set a bunch of default values for the settings, then hide the fieldset. Like @David_Rothstein suggested I used a hook_form_FORM_ID_alter() to set the defaults that I wanted, but I was never able to find the fieldset element in the $form variable, so I'm hiding the fieldset via css. Does anybody know how the fieldset is added to the $form object?

@dRaz, you'll need to put that custom code in a custom module, here is the code I used to set the defaults.

/**
 * Implements hook_form_FORM_ID_alter().
 */
function moduleName_form_media_gallery_node_form_alter(&$form, &$form_state, $form_id){
  $language = $form['language']['#value'];
  
  // Force number of rows.
  $form['media_gallery_rows'][$language][0]['value']['#default_value'] = 6;
  $form['media_gallery_rows'][$language]['#access'] = FALSE;
  
  // Force number of columns.
  // values: 2,3,4,5,6,7,8,9,10
  $form['media_gallery_columns'][$language]['#default_value'] = 3;
  $form['media_gallery_columns'][$language]['#access'] = FALSE;
  
  // Force download original image setting.
  // values: 0, 1
  $form['media_gallery_allow_download'][$language]['#default_value'] = 0;
  $form['media_gallery_allow_download'][$language]['#access'] = FALSE;
  
  // Force setting for image display.
  // values: lightbox, node
  $form['media_gallery_format'][$language]['#default_value'] = 'lightbox';
  $form['media_gallery_format'][$language]['#access'] = FALSE;
  
  // Force setting for image title.
  // values: hover, below, nothing
  $form['media_gallery_image_info_where'][$language]['#default_value'][0] = 'nothing';
  $form['media_gallery_image_info_where'][$language]['#access'] = FALSE;
  
  // Force show title and description setting.
  // values: 0, 1
  $form['media_gallery_lightbox_extras'][$language]['#default_value'] = 0;
  $form['media_gallery_lightbox_extras'][$language]['#access'] = FALSE;  
}
dRaz’s picture

Thanks bschilt,

Hopefully with a few heads working on this we can get this issue solved - seems weird that this cannot be done out of the box.

Moloc’s picture

Just as a additional information to comment #3.
The Media Gallery module uses the same hook, where media gallery adds the block and the fieldset. The media gallery hook implementation also moves all media gallery settings to the fieldset (from $form['media_gallery_rows'] to $form['settings_wrapper']['media_gallery_rows'] and so on.).

So, if your code in comment #3 works, then your hook is executed before the media gallery hook and all your changes are also moved.
So the question is, how do you know, if your hook is executed before the media_gallery hook or after? The answer is the module name (as i read somewhere; i also tested it).
If your module-name is alphabetical lower than "media_gallery" (for example "a_module", "b_module",...) then your hook is executed before the media_gallery hook, and therefore you can not see the fieldset and block settings.
If your module-name is alphabetical greater than "media_gallery" (for example "x_module", "z_module",...) then your hook is executed after the media_gallery hook, and therefore you can see the fieldset and block settings and modify them.
I hope that helps.

bschilt’s picture

@Moloc, you're right about the module weight being the issue here. My module started with an 'a' so it was being executed before media_gallery. I can't believe I blanked on this, its a common issue I run into a lot. anyway...

Add the following lines to the alter function I posted above to remove the settings and block fieldsets.

  // Remove the gallery settings fieldset
  $form['settings_wrapper']['#access'] = FALSE;
  
  // Remove the blocks fieldset (verticle tab)
  $form['block']['#access'] = FALSE;
dRaz’s picture

Fantastic work bschilt :) +10

David_Rothstein’s picture

As an alternative to changing the module name, you can instead change the module weight in the {system} table to make it run later, or (the best option) you can use hook_module_implements_alter(). That way you can target the specific hook you want (in this case 'form_alter') to run in the order you want it to.

Although the latter one will definitely be the best option soon, due to a bug it may not always work reliably at the moment though (see #765860: drupal_alter() fails to order modules correctly in some cases).

bschilt’s picture

After making sure your module's form alter function is called after media gallery use the following code to set the default settings and hide the fieldset:

  $language = $form['language']['#value'];
  
  // Force number of rows.
  $form['settings_wrapper']['gallery']['media_gallery_rows'][$language][0]['value']['#default_value'] = 6;
  
  // Force number of columns.
  // values: 2,3,4,5,6,7,8,9,10
  $form['settings_wrapper']['gallery']['media_gallery_columns'][$language]['#default_value'] = 3;
  
  // Force setting for image title.
  // values: hover, below, nothing
  $form['settings_wrapper']['gallery']['media_gallery_image_info_where'][$language]['#default_value'][0] = 'nothing';
  
  // Force download original image setting.
  // values: 0, 1
  $form['settings_wrapper']['presentation']['media_gallery_allow_download'][$language]['#default_value'] = 0;
  
  // Force setting for image display.
  // values: lightbox, node
  $form['settings_wrapper']['presentation']['media_gallery_format'][$language]['#default_value'] = 'lightbox';
  
  // Force show title and description setting.
  // values: 0, 1
  $form['settings_wrapper']['presentation']['media_gallery_lightbox_extras'][$language]['#default_value'] = 0;
  
  // Remove the gallery settings fieldset
  $form['settings_wrapper']['#access'] = FALSE;
  
  // Remove the blocks fieldset (verticle tab)
  $form['block']['#access'] = FALSE;

We no longer need to hide each field now that we're hiding the fieldset.

totap’s picture

Stupid question, but how and where implement this code to get rid of unwanted fieldsets?

dRaz’s picture

Hi to tap,

You need to create a new module yourself to use this code.

Create 2 files:

media_gallery_settings_hide.INFO
media_gallery_settings_hide.MODULE

Place these into a folder called media_gallery_settings_hide in your modules folder.

INFO file should contain:

name = media_gallery_settings_hide
description = Hide the settings in creating a gallery
core = 7.x
files[] = media_gallery_settings_hide.module

MODULE file should contain the code written in above post(s).

Upload these to your site's module folder and enable.

Hope this helped.

totap’s picture

Thank you dRaz very much:)
The code of bschilt #3 and #9 didn't worked for me, but now I know how to make modules :)

jkenters’s picture

I just started using Drupal, so I'm very sorry if the code below is the worst you have seen in years :-)

I could not get the code above to disable all I wanted. My module was named 'zzzcustom' with a high weight, so I thought zzzcustom_form_media_gallery_node_form_alter would be the last thing changing the form/tabs. But xdebug showed me this was not the case: the media_gallery hook was run after it because they used hook_module_implements_alter() to change the order. So, I did the same thing in my own module to get the desired effect:

/*
 * Implements hook_form_FORM_ID_alter().
 */
function zzzcustom_form_media_gallery_node_form_alter(&$form, &$form_state) {
  drupal_add_css('#edit-settings-wrapper {display: none;}', array('type' => 'inline'));
  $form['block']['#access'] = FALSE;
  $form['path']['#access'] = FALSE;
  $form['author']['#access'] = FALSE;
  $form['revision_information']['#access'] = FALSE;
}

/**
 * Implements hook_module_implements_alter().
 */
function zzzcustom_module_implements_alter(&$implementations, $hook) {
  switch ($hook) {
    case 'form_alter':
      if (!isset($implementations['zzzcustom'])){
        break;
      }
      $group = $implementations['zzzcustom'];
      unset($implementations['zzzcustom']);
      $implementations['zzzcustom'] = $group;
      break;
  }
}

Now all the fields/tabs I don't want are hidden to the user. Hope this helps someone.

ivnish’s picture

Issue summary: View changes
Status: Active » Closed (outdated)