Since I upgraded the addressfield module to version 7.x-1.3 all addressfields in custom forms are not showing up anymore.

This is the code I use to create an address field:

$form['address'] = array(
    '#type' => 'addressfield',
    '#title' => t('Mailing Address'),
    '#required' => TRUE,
    '#default_value' => array('country' => 'DE'),
  );

The form has some other elements. Everything but the addressfield works as expected.

Before the upgrade everything worked as expected and I did not do any related code changes, so I assume it has to do with the update. But downgrading back to version 1.2 didn't solve my problems neither, so I might wrong about this.

To make sure that his has nothing to do with my custom form, I tried to alter an existing form: the edit form of a node type:

/**
 * Implements hook_form_alter().
 */
function custom_misc_form_alter(&$form, $form_state, $form_id) {

  if($form_id == "article") {
      // Add a from element, to test whether or not the hook works.
      $form['test'] = array(
          '#type' => 'textfield',
          '#title' => t('Test'),
      );

      // Add an addressfield.
      $form['address'] = array(
         '#type' => 'addressfield',
         '#title' => t('Mailing Address'),
         '#required' => TRUE,
         '#default_value' => array('country' => 'DE'),
      );
  }  
}

While the test field shows up as expected the address field doesn't.
As I get no error message and could not find any hints, that the API has changed, I come to the conclusion, this must be a bug.

Comments

gunwald created an issue. See original summary.

gunwald’s picture

Ok, my fault, I had forgotten that the module has to be patched in order do use the field with form api. So I applied the patch form here: https://www.drupal.org/project/addressfield/issues/970048#comment-12432295 and it works again.

Would you consider to bring this patch upstream?

bojanz’s picture

Status: Active » Closed (duplicate)

Marking as duplicate, since there's already an issue about supporting addressfield as a form element.

And no, there is no plan to commit the patch in question, due to backwards compatibility.