
| Current Path : /var/www/html/store/web/modules/contrib/address/src/Repository/ |
Linux ift1.ift-informatik.de 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 |
| Current File : /var/www/html/store/web/modules/contrib/address/src/Repository/AddressFormatRepository.php |
<?php
namespace Drupal\address\Repository;
use CommerceGuys\Addressing\AddressFormat\AddressFormatRepository as ExternalAddressFormatRepository;
use Drupal\address\Event\AddressEvents;
use Drupal\address\Event\AddressFormatEvent;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
/**
* Provides address formats.
*
* Address formats are stored inside the base class, which is extended here to
* allow the definitions to be altered via events.
*/
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): array {
$definition = parent::processDefinition($countryCode, $definition);
// Allow other modules to alter the address format.
$event = new AddressFormatEvent($definition);
$this->eventDispatcher->dispatch($event, AddressEvents::ADDRESS_FORMAT);
$definition = $event->getDefinition();
return $definition;
}
}