Verify that the label for address_line3 is available

Created on 10 December 2024, 8 days ago

Problem/motivation

With the changes of 🐛 Require Address ~2.0 Active address_line3 was added. But this only available with address v2.

Steps to reproduce

  1. Install address v1
  2. Create a address field and select the address display as a formatter
  3. You should see a php warning:Warning: Undefined array key "addressLine3" in Drupal\address_display\Plugin\Field\FieldFormatter\AddressDisplayFormatter->getLabels() (line 115 of /var/www/html/web/modules/contrib/address_display/src/Plugin/Field/FieldFormatter/AddressDisplayFormatter.php)

Proposed resolution

Set address_line3 to NULL in case it is not set.

  private function getLabels() {
    $values = LabelHelper::getGenericFieldLabels();

    return [
      'given_name' => $values['givenName'],
      'additional_name' => $values['additionalName'],
      'family_name' => $values['familyName'],
      'organization' => $values['organization'],
      'address_line1' => $values['addressLine1'],
      'address_line2' => $values['addressLine2'],
      'address_line3' => $values['addressLine3'] ?? NULL, // Only available in address v2.
      'postal_code' => $values['postalCode'],
      'sorting_code' => $values['sortingCode'],
      'administrative_area' => $values['administrativeArea'],
      'locality' => $values['locality'],
      'dependent_locality' => $values['dependentLocality'],
      'country_code' => $this->t('Country code'),
      'langcode' => $this->t('Langcode'),
    ];
  }
🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇩🇪Germany tobiasb Berlin

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024