You are here

public function ProfileLabelSubscriber::onLabel in Commerce Core 8.2

Sets the customer profile label to the first address line.

This behavior is restricted to customer profile types.

Parameters

\Drupal\profile\Event\ProfileLabelEvent $event: The profile label event.

File

modules/order/src/EventSubscriber/ProfileLabelSubscriber.php, line 29

Class

ProfileLabelSubscriber

Namespace

Drupal\commerce_order\EventSubscriber

Code

public function onLabel(ProfileLabelEvent $event) {

  /** @var \Drupal\profile\Entity\ProfileInterface $order */
  $profile = $event
    ->getProfile();
  $profile_type = ProfileType::load($profile
    ->bundle());
  $customer_flag = $profile_type
    ->getThirdPartySetting('commerce_order', 'customer_profile_type');
  if ($customer_flag && $profile
    ->hasField('address') && !$profile
    ->get('address')
    ->isEmpty()) {
    $event
      ->setLabel($profile
      ->get('address')->address_line1);
  }
}