You are here

public function AddressEventsSubscriber::onInitialValues in Commerce Demo 8

Alters the initial values.

Parameters

\Drupal\address\Event\InitialValuesEvent $event: The initial values event.

File

src/EventSubscriber/AddressEventsSubscriber.php, line 25

Class

AddressEventsSubscriber

Namespace

Drupal\commerce_demo\EventSubscriber

Code

public function onInitialValues(InitialValuesEvent $event) {
  if ($event
    ->getFieldDefinition()
    ->getTargetEntityTypeId() == 'profile' && $event
    ->getFieldDefinition()
    ->getTargetBundle() == 'customer') {
    $new_values = $this
      ->getRandomAddress() + $event
      ->getInitialValues();
    $event
      ->setInitialValues($new_values);
  }
}