1

I'm working on an Entity where I created a field containing Address informations (like country, city and street).

The default Address Type in Drupal 8 supports only 2 lines for the street information. Is there a way to add an extra line?

1

I found a (partial solution), but new ideas are always well welcomed. I used the field organization as third row and then I rearranged the weights of the fields in this way:

function mymodule_form_alter(&$form, FormStateInterface $form_state, $form_id) {
    if ($form_id == 'specific_add_form' || $form_id == 'specific_edit_form' ) {
        $form['field_address']['widget'][0]['address']['#after_build'][] = 'mymodule_weight_change';
    }

}

function mymodule_weight_change($element, $form_state) {
    $element['country_code']['#weight'] = -10;
    $element['address_line1']['#weight'] = -7;
    $element['address_line2']['#weight'] = -5;
    $element['organization']['#weight'] = -2;
    $element['postal_code']['#weight'] = 5;
    $element['locality']['#weight'] = 10;

    return $element;
}

Endly I put the css of the organization label as display: none.

  • another way could be puts a new text field inside your entity and then using javascript to move the field inside tyhe form. – que le Sep 3 '18 at 12:47

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