|
Drupal 4,7 and the new one Forms API
last May 1 was published
officially the final version of Drupal 4,7, one of the license content agents
free more popular, writing in PHP. As it can be seen in the news published in
the page of the project, has passed slightly more than a year since began the
development of this branch. 1500 patches originating from 338 different
contributors have been counted, with which it is estimated that the community of
desarrolladores has multiplied for 6 with regard to the previous version. The
list of changes is available in the page of the news, but wanted to take
advantage of to speak of one of the most significant characteristics of that new
version: The new one API for forms.
In Drupal 4,7, the alteration,
extension or personalization of aspect of any form is almost immediate and quite
simple. Instead of composing a form creating directly the HTML code for the same
one, using the functions of aid for the generation of the labels, an associative
array is used where we go adding each one of the elements of our form with its
corresponding properties. The reference of elements, properties, and values by
defect for the properties of you determined elements, can be found in
drupaldocs.org. But we see an example of generation of a form. We imagine that
we want to create a form that collect information in two fields: Title
(obligatory) and photography (optional). The corresponding code would be the
following one:
$Form [' title'] = array (‘#type' => 'textfield', ‘#title' => t ('
Title'), ‘#required' => true, ‘#default_value' => $node->title); $form
[' _node_files'] [' photo'] = array (‘#type' => 'file', ‘#title' => t ('
Photo'), ‘#required' => false, ‘#default_value' => $node->node_files ['
photo']); Subsequently, of course, we would use the. There is a module already
prepared for this, call node_files. modulate, in the repository CVS of
contributions. But as it can be seen, to generate each one of the fields of our
form is very simple.
But we go beyond. Also we can
personalize existing forms. For example, we imagine that we want to simplify the
data insertion form of a determined type of node, so that they appear not you
determined preestablished fields by Drupal as the date of creation, the author,
or the button of previsualización. Therefore we can utilize hook_form_alter ()
to capture the variable that contains our form before be converted to HTML and
shown in the page, and to alter variable happiness in that that us plazca.
Continuing the example proposed, for a form called product_node_form, we would
be able to generate the following code:
If ($form_id == ‘product_node_form') {// Hidden the fieldset complete where
they appear author and date $form [' author'] [' #type'] = 'hidden'; // Hidden
the button of previsualización $form [' preview'] [' #type'] = 'hidden';} Also
we can do that a block of fields appear always unfolded, instead of showing the
title
The block with the hidden
fields:
// The block of categories will not be folding $form [' taxonomy'] ['
#collapsible'] = 0; OR even we can remove some fields of its block, to place
them to the same level that our fields Title
Photography:
// We Create a state field from the original one $form [' status'] = $form ['
options'] [' status']; // and we destroy the original one unset ($form[’
options'] [' status']); // we Create a field promoted from the original one
$form [' promote'] = $form [' options'] [' promote']; // and we destroy the
original one unset ($form[’ options'] [' promote']); In final, a new one
Necessary in each case.
If you desire to expand this
information, not to stop visiting the fast guide of Forms API in
drupaldocs.org.
All Inclusive Holidays
Looking for
holidays to Faliraki yesterday, I ended up booking all inclusive holidays
which I thought was a great deal. So I am looking forward to living it up and party time in
Rhodes this summer. Anyone wanting a great deal should check them out and we will have a great time.
Home Accessories
home accessories Luxury in white. Enjoy savings on luxury bedding, bathroom, kitchenware and accessories.
Get the best last minute holiday deal to cyprus, turkey, greece and spain
Online Video
online video ad platform video ad network SpotXchange has partnered with hundreds of publishers who represent tens of thousands of sites and tens of millions of daily video impression opportunities.
Mobile Phone Contracts
LG Secret Deals and all the latest and Best Mobile Phone Deals are always available from mobilephone-deal.com.
You will get the best mobile phone deal for nokia, lg, samsung, sony ericsson and motorola.
Local Mobile Deals offer the widest range or 5 Megapixel Mobile Contracts online.
With all the latest range of camera megapixel phones localmobiledeals.co.uk are the site to visit!
|