You are here

class AddressFormatRepository in Address 8

Provides address formats.

Address formats are stored inside the base class, which is extended here to allow the definitions to be altered via events.

Hierarchy

  • class \Drupal\address\Repository\AddressFormatRepository extends \CommerceGuys\Addressing\AddressFormat\AddressFormatRepository

Expanded class hierarchy of AddressFormatRepository

1 string reference to 'AddressFormatRepository'
address.services.yml in ./address.services.yml
address.services.yml
1 service uses AddressFormatRepository
address.address_format_repository in ./address.services.yml
Drupal\address\Repository\AddressFormatRepository

File

src/Repository/AddressFormatRepository.php, line 16

Namespace

Drupal\address\Repository
View source
class AddressFormatRepository extends ExternalAddressFormatRepository {

  /**
   * The event dispatcher.
   *
   * @var \Symfony\Component\EventDispatcher\EventDispatcherInterface
   */
  protected $eventDispatcher;

  /**
   * Creates an AddressFormatRepository instance.
   *
   * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher
   *   The event dispatcher.
   */
  public function __construct(EventDispatcherInterface $event_dispatcher) {
    $this->eventDispatcher = $event_dispatcher;
  }

  /**
   * {@inheritdoc}
   */
  protected function processDefinition($countryCode, array $definition) {
    $definition = parent::processDefinition($countryCode, $definition);

    // Allow other modules to alter the address format.
    $event = new AddressFormatEvent($definition);
    $this->eventDispatcher
      ->dispatch(AddressEvents::ADDRESS_FORMAT, $event);
    $definition = $event
      ->getDefinition();
    return $definition;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AddressFormatRepository::$eventDispatcher protected property The event dispatcher.
AddressFormatRepository::processDefinition protected function
AddressFormatRepository::__construct public function Creates an AddressFormatRepository instance.