The second part of the article contains the differences inherent in the Drupal Forms API for version 7. This part of the article is published as an open topic, visible not only to Drupal blog subscribers. But I will publish my further articles (on creating themes) as closed blog articles, so as not to disturb those who are not interested in Drupal.
In the
last article , we disassembled the functionality of a simple module that returned the entered name to the form using AJAX (referred to in Drupal 6 as “AHAH”). Now the turn of version 7.
')
1. The most interesting changes in the API Drupal 7
- In Drupal 7, info files have changed. Now, any files with php code included in the module ( inc and test files), you need to declare an info file. In our case, there are none.
- Changed way to handle AJAX. Now it is not necessary to set the path for handling via hook_menu , you can immediately specify the callback function.
- Request processing path is now system - / system / ajax .
- Changed processing forms. Now, the callback function receives two variables - an array of the form and a pointer to the state of the form.
2. Changes in the form code
Changes in the form code are minor. The principles of the Drupal Forms API remain the same.
2. Changes in the request processing code
The value of the
$ form_state array is quite large. It stores
all the data on the form and its condition . From there we take the value of our
name field.
If in Drupal 6 we sent the text that was displayed in case of success, via
drupal_json () , then in Drupal 7 we reassemble the form and add the
markup element to it. Markup is used to output html markup to a form. This element existed in version 6 of Drupal - but in version 7
its syntax has changed .
Now we have to display the form. We can make it a standard code from the previous article.
function render_fc_form() { $out = '<div id="fc-form-wrapper">'; $out .= drupal_render(drupal_get_form('fc_form')); $out .= '</div><!-- /.fc-form-->'; return $out; }
Please note that there are many more API changes in Drupal 7. Here is a
list of changes made to the Drupal API after version 6 concerning writing modules (for topics, a separate list).
Download the archive with the whole module