I know it's a newbie question, but it's take me a lot of time to find a a small code for a small fonctionality.

for example I wanted to make the address phone field required, I didn't know how to know the arrays keys.

 * Implements hook_field_widget_form_alter().
function organize_address_field_widget_form_alter(&$element, $form_state, $context) {
  if(!empty($element['#addressfield'])) {
    $element['country']['#weight'] = 100;
    $element['phone_block']['phone_number']['phone_number']['#required'] = TRUE;


I tried devel to find it but without result.

So my question,after finding the good hook, how I can know the variables to use.

Is a general question to help me to learn module development.

closed as too broad by kiamlaluno Jun 1 '15 at 20:34

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • @shawn The code in the question works well for me, I just gave an example to request explanation how I do if want write a similar code. – learner123 Jun 1 '15 at 8:15
  • If you need to clarify your question, you can go back and edit it again. The original version seemed like you were trying to make the field required. – Shawn Conn Jun 1 '15 at 12:04
  • @ShawnConn I reach my need by using kpr() and debug() functions. thank you – learner123 Jun 2 '15 at 9:57

May be I'm missing something: I don't understand why you want to programatically make the field required.

Required is not a feature of a field by itself, it is an option you can set on its instance once it's attached to a node, through the admin/structure/types/manage/yourContentType/fields/yourFieldName.

  • It doesn't work for address field module, because this module provide complex field. – kala4ek Jun 1 '15 at 4:28
  • sorry my question was edited, they understood me wrong, I won't request to know how to make this field required, but how to know variables to work with when writing code like above. I posted a general question. – learner123 Jun 1 '15 at 8:07

Not the answer you're looking for? Browse other questions tagged or ask your own question.