[support] D7 Trouble altering comment form

berliner myberliner at gmail.com
Sat Nov 2 00:06:46 UTC 2013


Hi,

see this stackexchange question for possible solutions:
http://drupal.stackexchange.com/questions/33305/is-it-possible-to-change-the-add-new-comment-text-on-certain-content-types 

I have searched google for 'drupal form alter "Add new comment“'.

best regards,
berliner

Am 02.11.2013 um 00:15 schrieb Jeff Greenberg <listmail.ayendesigns at gmail.com>:

> Ah, right! Thanks. So for the buttons, I really wanted to do:
> 
>         $form['actions']['submit'] = t('Post comment');
>         unset($form['actions']['preview']);
>  
> But what also is revealed is that the title Add new comment is not part of the form. I'd appreciate any idea regarding overriding its value. I tried using content: xxx in css, but while I can get the new value to appear doing that, I can't seem to hide the original one without hiding both.
> 
> 
> On Fri, Nov 1, 2013 at 3:30 PM, berliner <myberliner at gmail.com> wrote:
> What you did was to alter the node object that was passed into the form builder as an argument.
> Instead var_dump the entire $form array and look for keys that do not start with a dash. Those are the ones that will finally be rendered. Keys starting with a dash control how they are rendered.
> Take a look at the examples in the docs: https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_form_alter/7
> 
> best regards,
> berliner
> 
> Am 01.11.2013 um 19:34 schrieb Jeff Greenberg <listmail.ayendesigns at gmail.com>:
> 
> > I have the following code in my module:
> >
> >     function mymodule_form_alter(&$form, &$form_state, $form_id) {
> >       if ($form_id == 'comment_node_blog_form') {
> >         $form['#node']->content['links']['comment']['#links']['comment-add']['title'] = t('Post a comment');
> >         $form['#node']->actions['submit'] = t('Post comment');
> >         unset($form['#node']->actions['preview']);
> >     var_dump($form);
> >   }
> >
> > When I look at the var_dump, the form fields are set as intended. However, in looking at the form, the title still has "Add new comment", the submit button is unchanged, and the preview button is still present.
> >
> > In searching the page content (including the var_dump output) the ONLY place 'Add' exists is in the text of the form ... NOT in the content of the var_dump. The only way I can see that happening is if the form array is being changed back after my hook, so I tried changing the module weight to 99 (via mysql) and clearing cache. No difference.
> >
> >
> > --
> > ---
> > drupal.org/user/367108
> > linkedin.com/in/jeffrgreenberg
> > accidentalcoder.com / ayendesigns.com
> > @accidentalcoder
> > --
> > [ Drupal support list | http://lists.drupal.org/ ]
> 
> --
> [ Drupal support list | http://lists.drupal.org/ ]
> 
> 
> 
> -- 
> ---
> drupal.org/user/367108
> linkedin.com/in/jeffrgreenberg
> accidentalcoder.com / ayendesigns.com
> @accidentalcoder
> -- 
> [ Drupal support list | http://lists.drupal.org/ ]



More information about the support mailing list