You are here

class ProfileLabelSubscriber in Commerce Core 8.2

Hierarchy

  • class \Drupal\commerce_order\EventSubscriber\ProfileLabelSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of ProfileLabelSubscriber

1 string reference to 'ProfileLabelSubscriber'
commerce_order.services.yml in modules/order/commerce_order.services.yml
modules/order/commerce_order.services.yml
1 service uses ProfileLabelSubscriber
commerce_order.profile_label_subscriber in modules/order/commerce_order.services.yml
Drupal\commerce_order\EventSubscriber\ProfileLabelSubscriber

File

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

Namespace

Drupal\commerce_order\EventSubscriber
View source
class ProfileLabelSubscriber implements EventSubscriberInterface {

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    $events = [
      'profile.label' => 'onLabel',
    ];
    return $events;
  }

  /**
   * Sets the customer profile label to the first address line.
   *
   * This behavior is restricted to customer profile types.
   *
   * @param \Drupal\profile\Event\ProfileLabelEvent $event
   *   The profile label event.
   */
  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);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ProfileLabelSubscriber::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
ProfileLabelSubscriber::onLabel public function Sets the customer profile label to the first address line.