generateSampleValue

Created on 16 October 2016, over 8 years ago
Updated 10 September 2024, 7 months ago

Can we have, before a 1.0 release, an implementation of
Drupal\address\Plugin\Field\FieldType\AddressItem::generateSampleValue ?
Here's the code I'm using as a placeholder...

  /**
   * {@inheritdoc}
   */
  public static function generateSampleValue(\Drupal\Core\Field\FieldDefinitionInterface $field_definition) {
    $random = new \Drupal\Component\Utility\Random();
    $countries = $field_definition->getSetting('available_countries') ?: array_keys(\Drupal::service('address.country_repository')->getList());
    return [
      'langcode' => 'en',
      'country_code' => $countries[array_rand($countries)],
      'administrative_area' => 'NY',
      'locality' => $random->word(mt_rand(5, 12)),
      'dependent_locality' => 'Brooklyn',
      'postal_code' => mt_rand(1, 9999),
      'sorting_code' => mt_rand(1, 9999),
      'address_line1' => mt_rand(1, 999) .', '.$random->word(mt_rand(3, 5)),
      'address_line2' => $random->sentences(3),
      'organization' => $random->word(mt_rand(5, 12)),
      'given_name' => $random->word(10),
      'additional_name' => $random->word(10),
      'family_name' => $random->word(10)
    ];
  }
πŸ“Œ Task
Status

Needs review

Version

1.0

Component

Code

Created by

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024