tags:

views:

97

answers:

3

Im getting T_String error on this code, its saying more accuratly on the 2nd line ($form['com...) and i simply cant see why.

function _maxlength_comment_type_form_alter(&$form, $form_state, $form_id) {
    $form['comment']['comment_max_length'] = array(
     '#type' => 'select',
     '#title' => t('Maximum comment length'),
     '#default_value' => variable_get('comment_max_length_'. $form['#node_type'] -> type, 160),
     '#options'=> drupal_map_assoc(array(140,160,180,200)),
     '#description' => t('numero maximo de caracteres permitidos.'),
     '#weight' => -1,
     );

Im adding this code to Maxlength drupal module.

+1  A: 

It might be this part:

'comment_max_length_'. $form['#node_type'] -> type

Try getting rid of the spaces around the arrow?


Edit - I don't believe the above is actually a problem with the code, though I'd still recommend removing the spaces as a matter of style, just so it's plainly obvious that you're doing this:

'comment_max_length_'. ($form['#node_type']->type)

rather than this:

('comment_max_length_' . $form['#node_type'])

Your code is valid and Works On My PCTM.


Another edit:

Make sure that $form['comment'] has been defined as well. Perhaps add this at the start of the function.

if (!isset($form['comment'])) $form['comment'] = array();
nickf
Thanks for the syntax hints guys, im still learning php (noobie) so i probly do a lot of mistakes of this type.Btw i found the problem, it was in a function right after the one i posted. I still need to read better the parse errors. They acuse one line but the error is actually in another?
fabio
yes, often the problem will be on the line before or after the line which it says.
nickf
A: 

Two problems I can see, the one nickf alluded to above, i.e. you shouldn't have a space either side of the arrow:

'comment_max_length_'. $form['#node_type'] -> type

Additionally, this shouldn't have a comma after it (as it's the last item in the array):

'#weight' => -1,`
James Burgess
It's not actually a syntax error. It's poor style, IMO, but it's still valid PHP.
nickf
The extra comma doesn't matter. I usually add that extra comma in my code. That way, when I later add more entries to the array I don't forget about adding the extra comma. Also, my diffs will be smaller.
Sander Marechal
It's not usually a problem, but IIRC (feel free to correct me if I'm wrong), some older PHP implementations do error on the extra comma. Maybe I'm just dreaming, though :)
James Burgess
A: 

How about breaking that huge statement into smaller ones so you can pinpoint the problem better?

Michael Borgwardt
That helped a lot, i took out function by function so i could actually find where the error was at
fabio