I have been trying to change the add node form but node-form, the name of the form does not seem to respond to hook_form_alter. Is this a bug or is there another name that can be used in the code?


/**
 * Implementation of hook_form_alter().
 */
function flashgame_form_alter($form_id, &$form) {
  
  if ($form_id == 'node_form'){  
      unset($form['title']);         
  }
  
}

Comments

carlmcdade’s picture

Also tried with:

/**
* Implementation of hook_form_alter().
*/
function flashgame_form_alter($form_id, &$form) {
 
  if ($form_id == 'node-form'){ 
      unset($form['title']);        
  }
 
}

and

/**
* Implementation of hook_form_alter().
*/
function flashgame_form_alter($form_id, &$form) {
 
  if ($form_id == 'flashgame-node-form'){ 
      unset($form['title']);        
  }
 
}

without any luck

Hiveminds Magazine
http://www.hiveminds.co.uk
for web publishers and community builders CMS Demo Matrix
Coming soon!Drupal Support | Drupal S

heine’s picture

Because the form_id is not node_form, but [content type]_node_form eg. story_node_form for the story node submission form.

To circumvent check whether $form['#id'] is node-form or $form['#base'] (5.x) is node_form.

Yet another possibility is to check $form_id == $form['type']['#value']_node_form (add the necessary isset checks).

--
The Manual | Troubleshooting FAQ | Tips for posting | How to report a security issue.

carlmcdade’s picture

Thanks that got. Is there a handbook page or API doc on this? The only thing I found seemed the pertain to phptemplate and not hook_form_alter.

Hiveminds Magazine
http://www.hiveminds.co.uk
for web publishers and community builders CMS Demo Matrix
Coming soon!Drupal Support | Drupal S

heine’s picture

Apart from some examples in core code and reading node module / api.drupal.org, not that I know.

You can however download a 4.7 version of Form Inspect from svn://heine.familiedeelstra.com/public/modules/devel_forminspect (subversion required). Depends on the devel module.

Form Inspect basically provides an automatic var_dump of the current forms array.
--
The Manual | Troubleshooting FAQ | Tips for posting | How to report a security issue.

carlmcdade’s picture

another small question in the same line.


if ($form_id == 'flashgame_node_form'){
      
        $form['taxonomy']['2'] = array(
          '#description' => t('Please choose a category for this game.'));
                     
  }

Does not seem to go with the droplist of terms. While $form['taxonomy'] does exist and can be altered I cannot get in contact with its children.

Hiveminds Magazine
http://www.hiveminds.co.uk
for web publishers and community builders CMS Demo Matrix
Coming soon!Drupal Support | Drupal S

heine’s picture

I'd guess your changes are overwritten by taxonomy module (if it has the same weight as flashgame.module, it will run later).

--
The Manual | Troubleshooting FAQ | Tips for posting | How to report a security issue.

carlmcdade’s picture

Hmm,

Tried changing the load weight but got nothing.

Inspector is only 5.0x and all our sites are 4.7. Have any idea if inspector will work with the backport module installed?

Hiveminds Magazine
http://www.hiveminds.co.uk
for web publishers and community builders CMS Demo Matrix
Coming soon!Drupal Support | Drupal S

heine’s picture

You can however download a 4.7 version of Form Inspect from svn://heine.familiedeelstra.com/public/modules/devel_forminspect

--
The Manual | Troubleshooting FAQ | Tips for posting | How to report a security issue.

carlmcdade’s picture

Okay, got it from svn and installed. But you know what? It sees every element array except for those that come from taxonomy module.
I have a droplist with terms that just does not show upon inspection of the $form array.

Menu settings also does not appear in the arrays. I tried grabbing them with form_alter and got nothing.

Hiveminds Magazine
http://www.hiveminds.co.uk
for web publishers and community builders CMS Demo Matrix
Coming soon!Drupal Support | Drupal S

heine’s picture

Thanks.

Small error in the install file (that's what you get when renaming).

To remedy, execute the query:

UPDATE system SET weight = 100 WHERE name = 'devel_forminspect';

--
The Manual | Troubleshooting FAQ | Tips for posting | How to report a security issue.

carlmcdade’s picture

Yeah, I caught that and set the weight to 89 after the devel module manually. I set the weight of flashgame.module to 90 and then saved the configuration a cople of times. Nothing changed :(

Very frustrating.

Hiveminds Magazine
http://www.hiveminds.co.uk
for web publishers and community builders CMS Demo Matrix
Coming soon!Drupal Support | Drupal S

heine’s picture

Then I can't help you without seeing further code & more info.

I see both taxonomy and menu just fine.

Just note that the taxonomy structure is

['taxonomy'][$vid] = array( ... select element ... );

So, when you just want to overwrite the description of vocabulary 2 you'll need

$form['taxonomy'][2][#description'] = t('My new description');

Your example above would overwrite the definition.
--
The Manual | Troubleshooting FAQ | Tips for posting | How to report a security issue.

carlmcdade’s picture

thanks,

Here is the code I am using now followed in the next post with the outpu from form inspect.

/**
 * Implementation of hook_form_alter().
 */
function flashgame_form_alter($form_id, &$form) {
  // hide critical options from forum vocabulary
  if ($form_id == 'taxonomy_form_vocabulary') {
    if ($form['vid']['#value'] == _flashgame_get_vid()) {
      $form['help_forum_vocab'] = array(
        '#value' => t('This is the designated flash game vocabulary. 
         Some of the normal vocabulary options have been removed.'),
        '#weight' => -1
      );
      
      $form['nodes']['flashgame'] = array(
        '#type' => 'checkbox', 
        '#value' => 1, 
        '#title' => t('flash game'), 
        '#attributes' => array('disabled' => ''), 
        '#description' => t('This flash game node type is attached to the flash game vocabulary.'));
        
      $form['hierarchy'] = array(
        '#type' => 'value', 
        '#value' => 1);
        
      unset($form['relations']);
      unset($form['tags']);
      unset($form['multiple']);
      
      $form['required'] = array(
        '#type' => 'value',
        '#value' => 1);
    }
    else {
      unset($form['nodes']['flashgame']);
    }
  }
  
	if ($form_id == 'flashgame_node_form') {
		$form['taxonomy'] = array('#description' => t('This a desciption of the category list fieldset'));
    $form['taxonomy']['2'] = array('#description' => t('This a desciption of the category list droplist'));
  }
  
}

Hiveminds Magazine
http://www.hiveminds.co.uk
for web publishers and community builders CMS Demo Matrix
Coming soon!Drupal Support | Drupal S

carlmcdade’s picture

Array
(
    [#id] => node-form
    [nid] => Array
        (
            [#type] => value
            [#value] => 
        )

    [vid] => Array
        (
            [#type] => value
            [#value] => 
        )

    [uid] => Array
        (
            [#type] => value
            [#value] => 1
        )

    [created] => Array
        (
            [#type] => value
            [#value] => 1173079509
        )

    [type] => Array
        (
            [#type] => value
            [#value] => flashgame
        )

    [changed] => Array
        (
            [#type] => hidden
            [#default_value] => 
        )

    [title] => Array
        (
            [#type] => textfield
            [#title] => Subject2
            [#default_value] => 
            [#required] => 1
            [#weight] => -5
        )

    [body_filter] => Array
        (
            [body] => Array
                (
                    [#type] => textarea
                    [#title] => Body
                    [#default_value] => 
                    [#rows] => 20
                    [#required] => 1
                )

        )

    [flashgames] => Array
        (
            [#type] => select
            [#title] => Flashgames
            [#default_value] => 
            [#rows] => 20
            [#options] => Array
                (
                    [0] => none found
                )

            [#weight] => -5
            [#description] => Choose a game to be shown in this area.
            [#required] => 1
        )

    [#node] => stdClass Object
        (
            [uid] => 1
            [name] => admin
            [type] => flashgame
            [created] => 1173079509
            [date] => 2007-03-05 07:25:09 +0000
            [comment] => 2
            [status] => 1
            [moderate] => 
            [promote] => 1
            [sticky] => 
            [revision] => 
        )

    [author] => Array
        (
            [#type] => fieldset
            [#title] => Authoring information
            [#collapsible] => 1
            [#collapsed] => 1
            [#weight] => 20
            [name] => Array
                (
                    [#type] => textfield
                    [#title] => Authored by
                    [#maxlength] => 60
                    [#autocomplete_path] => user/autocomplete
                    [#default_value] => admin
                    [#weight] => -1
                    [#description] => Leave blank for <em>Anonymous</em>.
                )

            [date] => Array
                (
                    [#type] => textfield
                    [#title] => Authored on
                    [#maxlength] => 25
                    [#description] => Format: 2007-03-05 07:25:09 +0000. Leave blank to use the time of form submission.
                )

        )

    [options] => Array
        (
            [#type] => fieldset
            [#title] => Publishing options
            [#collapsible] => 1
            [#collapsed] => 1
            [#weight] => 25
            [status] => Array
                (
                    [#type] => checkbox
                    [#title] => Published
                    [#default_value] => 1
                )

            [moderate] => Array
                (
                    [#type] => checkbox
                    [#title] => In moderation queue
                    [#default_value] => 
                )

            [promote] => Array
                (
                    [#type] => checkbox
                    [#title] => Promoted to front page
                    [#default_value] => 1
                )

            [sticky] => Array
                (
                    [#type] => checkbox
                    [#title] => Sticky at top of lists
                    [#default_value] => 
                )

            [revision] => Array
                (
                    [#type] => checkbox
                    [#title] => Create new revision
                    [#default_value] => 
                )

        )

    [preview] => Array
        (
            [#type] => button
            [#value] => Preview
            [#weight] => 40
        )

    [submit] => Array
        (
            [#type] => submit
            [#value] => Submit
            [#weight] => 45
        )

    [#after_build] => Array
        (
            [0] => node_form_add_preview
        )

    [#type] => form
    [#token] => flashgame_node_form
    [form_token] => Array
        (
            [#id] => edit-flashgame-node-form-form-token
            [#type] => token
            [#default_value] => beb27e7777faa9495deb548b07e31171
        )

    [form_id] => Array
        (
            [#type] => hidden
            [#value] => flashgame_node_form
            [#id] => edit-flashgame-node-form
        )

    [#description] => 
    [#attributes] => Array
        (
        )

    [#required] => 
    [#tree] => 
    [#parents] => Array
        (
        )

    [#method] => post
    [#action] => /drupal476/?q=node/add/flashgame
    [#validate] => Array
        (
            [node_form_validate] => Array
                (
                )

        )

    [#submit] => Array
        (
            [node_form_submit] => Array
                (
                )

        )

    [comment_settings] => Array
        (
            [#type] => fieldset
            [#title] => Comment settings
            [#collapsible] => 1
            [#collapsed] => 1
            [#weight] => 30
            [comment] => Array
                (
                    [#type] => radios
                    [#parents] => Array
                        (
                            [0] => comment
                        )

                    [#default_value] => 2
                    [#options] => Array
                        (
                            [0] => Disabled
                            [1] => Read only
                            [2] => Read/Write
                        )

                )

        )

)

Hiveminds Magazine
http://www.hiveminds.co.uk
for web publishers and community builders CMS Demo Matrix
Coming soon!Drupal Support | Drupal S

carlmcdade’s picture

form inspect? I tried with the default page module and some taxonomy and saw nothing there or in menu. So it might be the 4.7 version of form inspect does not have the capability to see them?

Hiveminds Magazine
http://www.hiveminds.co.uk
for web publishers and community builders CMS Demo Matrix
Coming soon!Drupal Support | Drupal S

carlmcdade’s picture

Solved.

Okay, so it was my db connection. When I made the changes in weight I saw them but Drupal was connected to a different database. Someone changed the db connection so when I copied the files locally to my machine I was still connecting to the older version of the database.

Thanks heine for all the help.

Hiveminds Magazine
http://www.hiveminds.co.uk
for web publishers and community builders CMS Demo Matrix
Coming soon!Drupal Support | Drupal S