Hi people,
I am moving Free Software Magazine to Drupal 7.
I am not very good with Drupal, and jumping to Drupal 7 is really quite _something_...
Now, I used ot have this fancy way to make sure that contributors could only chose Markdown for their articles:
function www_fsm_com_form_alter($form_id, &$form){
// Force the blogs as the same format as the articles
if($form_id == 'blog_node_form' || $form_id == 'book_node_form'){
unset($form['body_filter']['filter']);
$form['format'] = array('#type' => 'value', '#value' => variable_get('node_article_format_id', 0) );
}
}
And it worked!
Now, the same thing won't work: even after changing to the new form_alter function, it seems like the $form just doesn't have NEITHER the body NOR the input type.
After a bit of digging, I came out with this:
function www_fsm_com_element_info_alter(&$type) {
if($type['form']['#action'] == '/node/add/blog'){
$type['text_format']['#process'][] = 'www_fsm_com_process_format';
}
#drupal_set_message("Type is ".print_r($type,TRUE));
}
function www_fsm_com_process_format(&$element){
drupal_set_message("CALLED!!!" .print_r($element,TRUE) );
$element['format']['format']['#options'] = array( 7 => 'Markdown for Articles');
return $element;
}
From my limited understanding just looking at the code, it looks like Drupal now deals with "formattable" fields in a very different way. Now, my solution is limited (you can always go back and change the format, for example). But it works for now...
BUT, this is really bugging me.
Would somebody please explain:
* Did I do this half right?
* What does hook_element_info_alter() _actually_ do? What is it actually used for?
It took me _ages_ to get to this point. I am really eager to upgrade Free Software Magazine (it _really_ needs it), but this is driving me seriously insane :D
(more insane than figuring out how to find all the nodes that are using a specific input type, but that's a different story...)
Thank you in advance!
Merc.
Comments
Subscribe!
(that's how it used to work...)
I could...
Hi,
I could change the IF into this, so that I can also cover the editing phase...
a simpler solution
why cant you use http://drupal.org/project/better_formats ? You can achieve the same without writing a piece of code? It's not production ready for D7 as of now (you can test and help the module), but in D6 it is one of the coolest module that I have used for many websites.
Well...
Hi,
Well, the thing is, I *am* using D7 which is part of the problem...
(Yes, reading better_format is what made it possible for me to write this code!)
Merc.
Well...
Hi,
Well it looks like I asked one of those obscure questions that nobody really knows about :D
If anybody here feels like shedding some light on what hook_element_info_alter() does, I am all ears!
Merc.