after_build

Events happening in the community are now at Drupal community events on www.drupal.org.
jdidelet's picture

Hi everyone,

Anyone knows how we can use after_build to modify the value of an nodereference widget field? I would like to overwrite a select field (nodereference widget) and I don't know why.

Comments

My use case of #after_build

hswong3i's picture

My use case of #after_build in reCAPTCHA module patch: http://edin.no-ip.com/blog/hswong3i/patching-drupal-recaptcha-module-lib.... As your reference:

Index: recaptcha.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/recaptcha/Attic/recaptcha.admin.inc,v
retrieving revision 1.1.2.2
diff -u -p -r1.1.2.2 recaptcha.admin.inc
--- recaptcha.admin.inc 19 May 2010 17:29:37 -0000 1.1.2.2
+++ recaptcha.admin.inc 22 Dec 2010 13:11:06 -0000
@@ -14,6 +14,14 @@ function recaptcha_admin_settings() {
   _recaptcha_load_library();

   $form = array();
+  $form['recaptcha_library_path'] = array(
+    '#type' => 'textfield',
+    '#title' => t('recaptcha-php library path'),
+    '#default_value' => variable_get('recaptcha_library_path', RECAPTCHA_DEFAULT_LIBRARY_PATH),
+    '#description' => t('The location where recaptcha-php is installed. Relative paths are from the Drupal root directory.'),
+    '#required' => TRUE,
+    '#after_build' => array('_recaptcha_admin_settings_check_library_path'),
+  );
   $form['recaptcha_public_key'] = array(
     '#type' => 'textfield',
     '#title' => t('Public Key'),
@@ -84,3 +92,11 @@ function recaptcha_admin_settings_valida
     form_set_error('recaptcha_tabindex', t('The Tab Index must be an integer.'));
   }
}
+
+function _recaptcha_admin_settings_check_library_path($form_element) {
+  $library_path = $form_element['#value'];
+  if (!is_dir($library_path) || !(file_exists($library_path .'/recaptchalib.php'))) {
+    form_set_error($form_element['#parents'][0], t('The recaptcha-php files <em>recaptchalib.php</em> could not be found in the %library_path directory.', array('%library_path' => $library_path)));
+  }
+  return $form_element;
+}

Edison Wong
CEO, Co-founder
PantaRei Design Limited

Finally, I founded. I

jdidelet's picture

Finally, I founded. I copy/paste if I can help someone:

function your_module_name_form_alter(&$form, &$form_state, $form_id) {
  $form['#after_build'][] = 'your_module_name_your_function';
}

function your_module_name_your_function($form, &$form_state) {
  switch ($form['form_id']['#value']) {
    case 'the_name_of_your_form':
      $form['the_name_of_your_field']['nid']['nid']['#options'] = your_value; //(or your function)
      break;
  }
  return $form;
}

Julien Didelet
Founder
Weblaa.com

api.drupal.org has a great

dalin's picture

api.drupal.org has a great reference for all your FAPI questions:

http://api.drupal.org/api/drupal/developer--topics--forms_api_reference....

--


Dave Hansen-Lange
Director of Technical Strategy, Advomatic.com
Pronouns: he/him/his

DrupalHK

Group categories

HKDUG Vocabulary

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: