Añadir un botón «Volver» o «Cancelar» a los formularios de Drupal 7
12 marzo, 2014
Añadir un botón que implemente una acción de «Cancelar» o «Volver» a un formulario de creación de contenidos en Drupal es bastante sencillo, con un par de funciones que podemos implementar en el fichero template.php de nuestra plantilla, o en un pequeño módulo personalizado:
<?php /** * Implements hook_form_alter(). */ function modulename_form_alter(&$form, &$form_state, $form_id) { // You might want to filter by content type. if ($form_id == 'ctype_node_form') { // Add a cancel button. $form['actions']['cancel'] = array( '#type' => 'submit', '#value' => t('Cancel'), '#access' => TRUE, '#weight' => 15, '#submit' => array('modulename_form_cancel', 'node_form_submit_build_node'), '#limit_validation_errors' => array(), ); } } /** * Custom cancel button callback. */ function modulename_form_cancel($form, &$form_state) { $url = $_GET['destination'] ? $_GET['destination'] : 'choose/your/path'; drupal_goto($url); }
Las secciones a personalizar son:
- form_id: será el formulario para el cual queremos implementar la comprobación.
- ctype_node_form: aquí habrá que personalizar el nombre del tipo de contenido. Por ejemplo, pagina_node_form
- modulename: aquí iría el nombre del módulo personalizado o la plantilla de Drupal
Una opción para añadirlo a cualquier formulario de creación de contenido es el siguiente código:
<?php /** * Implements hook_form_alter(). */ function modulename_form_alter(&$form, &$form_state, $form_id) { // You might want to filter by content type. if (strpos($form_id, '_node_form') !== false ) { // Add a cancel button. $form['actions']['cancel'] = array( '#type' => 'submit', '#value' => t('Cancel'), '#access' => TRUE, '#weight' => 15, '#submit' => array('modulename_form_cancel', 'node_form_submit_build_node'), '#limit_validation_errors' => array(), ); } } /** * Custom cancel button callback. */ function modulename_form_cancel($form, &$form_state) { $url = $_GET['destination'] ? $_GET['destination'] : 'choose/your/path'; drupal_goto($url); }
Vía | Gist en Github de Pascualduez.
I’m all over the place with daily word counts. Some days I only write 250 words. Other days I write 5,000. On a rare day, I’ll get out 107820.I,;d like to increase my output, and am setting goals to that end for 2012, but I still wrote about 300,000 words total of new fiction in 2011, and for me that’s not too shabby.
Es un goce encontrar a alguien que realmente sabe lo que están hablando en Internet . Con seguridad, que sabes cómo llevar un post a la luz y que sea adictivo. Más gente tiene que leer esto.
hOur company offers a wide variety of non prescription drugs. Visit our health website in case you want to to improve your health with a help generic supplements. Our company offers herb-based health products. Take a look at our health contributing site in case you want to feel healthier. Our company offers herb-based pharmacy. Visit our health contributing portal in case you want to look healthier. Our company offers a wide variety of non prescription products. Look at our health website in case you want to look better with a help general health products. Our company offers a wide variety of health and related products. Look at our health contributing portal in case you want to look healthier. Our company provides a wide variety of weight loss products. Look at our health contributing portal in case you want to feel better.
Our company provides non prescription products. Visit our health contributing website in case you want to feel healthier. Our company offers herb-based supplements. Look at our health contributing portal in case you want to feel healthier. Our site offers a wide variety of non prescription drugs. Look at our health website in case you want to to feel healthier. Our company offers a wide variety of weight loss products. Take a look at our health contributing portal in case you want to strengthen your health. Our company provides a wide variety of non prescription products. Take a look at our health portal in case you want to look better with a help of generic supplements.