Unverified Commit bd4c5f07 authored by alexpott's avatar alexpott
Browse files

Issue #3055194 by catch, mikelutz, longwave, mkalkbrenner, hchonov: [Symfony...

Issue #3055194 by catch, mikelutz, longwave, mkalkbrenner, hchonov: [Symfony 5] The signature of the "Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher::dispatch()" method should be updated to "dispatch($event, string $eventName = null)", not doing so is deprecated since Symfony 4.3
parent 065f4812
......@@ -6,6 +6,8 @@
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Contracts\EventDispatcher\Event as ContractsEvent;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface as ContractsEventDispatcherInterface;
/**
* A performance optimized container aware event dispatcher.
......@@ -86,9 +88,19 @@ public function __construct(ContainerInterface $container, array $listeners = []
/**
* {@inheritdoc}
*/
public function dispatch($event_name, Event $event = NULL) {
if ($event === NULL) {
$event = new Event();
public function dispatch($event/*, string $event_name = NULL*/) {
$event_name = 1 < \func_num_args() ? func_get_arg(1) : NULL;
if (\is_object($event)) {
$event_name = $event_name ?? \get_class($event);
}
elseif (\is_string($event) && (NULL === $event_name || $event_name instanceof ContractsEvent || $event_name instanceof Event)) {
@trigger_error('Calling the Symfony\Component\EventDispatcher\EventDispatcherInterface::dispatch() method with a string event name as the first argument is deprecated in drupal:9.1.0, an Event object will be required instead in drupal:10.0.0. See https://www.drupal.org/node/3154407', E_USER_DEPRECATED);
$swap = $event;
$event = $event_name ?? new Event();
$event_name = $swap;
}
else {
throw new \TypeError(sprintf('Argument 1 passed to "%s::dispatch()" must be an object, %s given.', ContractsEventDispatcherInterface::class, \gettype($event)));
}
if (isset($this->listeners[$event_name])) {
......
......@@ -7,7 +7,8 @@
"require": {
"php": ">=7.3.0",
"symfony/dependency-injection": "^4.4",
"symfony/event-dispatcher": "^4.4"
"symfony/event-dispatcher": "^4.4",
"symfony/event-dispatcher-contracts": "^1.1"
},
"autoload": {
"psr-4": {
......
......@@ -228,7 +228,7 @@ public function save($has_trusted_data = FALSE) {
Cache::invalidateTags($this->getCacheTags());
}
$this->isNew = FALSE;
$this->eventDispatcher->dispatch(ConfigEvents::SAVE, new ConfigCrudEvent($this));
$this->eventDispatcher->dispatch(new ConfigCrudEvent($this), ConfigEvents::SAVE);
$this->originalData = $this->data;
return $this;
}
......@@ -245,7 +245,7 @@ public function delete() {
Cache::invalidateTags($this->getCacheTags());
$this->isNew = TRUE;
$this->resetOverriddenData();
$this->eventDispatcher->dispatch(ConfigEvents::DELETE, new ConfigCrudEvent($this));
$this->eventDispatcher->dispatch(new ConfigCrudEvent($this), ConfigEvents::DELETE);
$this->originalData = $this->data;
return $this;
}
......
......@@ -260,7 +260,7 @@ public function rename($old_name, $new_name) {
// Prime the cache and load the configuration with the correct overrides.
$config = $this->get($new_name);
$this->eventDispatcher->dispatch(ConfigEvents::RENAME, new ConfigRenameEvent($config, $old_name));
$this->eventDispatcher->dispatch(new ConfigRenameEvent($config, $old_name), ConfigEvents::RENAME);
return $this;
}
......
......@@ -640,7 +640,7 @@ protected function processMissingContent(&$context) {
if (!empty($missing_content)) {
$event = new MissingContentEvent($missing_content);
// Fire an event to allow listeners to create the missing content.
$this->eventDispatcher->dispatch(ConfigEvents::IMPORT_MISSING_CONTENT, $event);
$this->eventDispatcher->dispatch($event, ConfigEvents::IMPORT_MISSING_CONTENT);
$sandbox['missing_content']['data'] = $event->getMissingContent();
}
$current_count = count($sandbox['missing_content']['data']);
......@@ -660,7 +660,7 @@ protected function processMissingContent(&$context) {
* The batch context.
*/
protected function finish(&$context) {
$this->eventDispatcher->dispatch(ConfigEvents::IMPORT, new ConfigImporterEvent($this));
$this->eventDispatcher->dispatch(new ConfigImporterEvent($this), ConfigEvents::IMPORT);
// The import is now complete.
$this->lock->release(static::LOCK_NAME);
$this->reset();
......@@ -742,7 +742,7 @@ public function validate() {
$this->logError($this->t('Rename operation for simple configuration. Existing configuration @old_name and staged configuration @new_name.', ['@old_name' => $names['old_name'], '@new_name' => $names['new_name']]));
}
}
$this->eventDispatcher->dispatch(ConfigEvents::IMPORT_VALIDATE, new ConfigImporterEvent($this));
$this->eventDispatcher->dispatch(new ConfigImporterEvent($this), ConfigEvents::IMPORT_VALIDATE);
if (count($this->getErrors())) {
$errors = array_merge(['There were errors validating the config synchronization.'], $this->getErrors());
throw new ConfigImporterException(implode(PHP_EOL, $errors));
......
......@@ -378,7 +378,7 @@ public function getConfigEntitiesToChangeOnDependencyRemoval($type, array $names
public function getConfigCollectionInfo() {
if (!isset($this->configCollectionInfo)) {
$this->configCollectionInfo = new ConfigCollectionInfo();
$this->eventDispatcher->dispatch(ConfigEvents::COLLECTION_INFO, $this->configCollectionInfo);
$this->eventDispatcher->dispatch($this->configCollectionInfo, ConfigEvents::COLLECTION_INFO);
}
return $this->configCollectionInfo;
}
......
......@@ -85,7 +85,7 @@ public function getStorage() {
}
self::replaceStorageContents($this->active, $this->storage);
$this->eventDispatcher->dispatch(ConfigEvents::STORAGE_TRANSFORM_EXPORT, new StorageTransformEvent($this->storage));
$this->eventDispatcher->dispatch(new StorageTransformEvent($this->storage), ConfigEvents::STORAGE_TRANSFORM_EXPORT);
return new ReadOnlyStorage($this->storage);
}
......
......@@ -117,7 +117,7 @@ public function transform(StorageInterface $storage) {
self::replaceStorageContents($storage, $mutable);
// Dispatch the event so that event listeners can alter the configuration.
$this->eventDispatcher->dispatch(ConfigEvents::STORAGE_TRANSFORM_IMPORT, new StorageTransformEvent($mutable));
$this->eventDispatcher->dispatch(new StorageTransformEvent($mutable), ConfigEvents::STORAGE_TRANSFORM_IMPORT);
// Return the storage with the altered configuration.
return $mutable;
......
......@@ -4,6 +4,7 @@
use Composer\Autoload\ClassLoader;
use Drupal\Component\Assertion\Handle;
use Symfony\Component\EventDispatcher\Event;
use Drupal\Component\FileCache\FileCacheFactory;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\Cache\DatabaseBackend;
......@@ -952,7 +953,7 @@ protected function initializeContainer() {
// Allow other parts of the codebase to react on container initialization in
// subrequest.
if (!empty($subrequest)) {
$this->container->get('event_dispatcher')->dispatch(self::CONTAINER_INITIALIZE_SUBREQUEST_FINISHED);
$this->container->get('event_dispatcher')->dispatch(new Event(), self::CONTAINER_INITIALIZE_SUBREQUEST_FINISHED);
}
// If needs dumping flag was set, dump the container.
......
......@@ -76,7 +76,7 @@ public function onEntityTypeCreate(EntityTypeInterface $entity_type) {
$this->entityLastInstalledSchemaRepository->setLastInstalledFieldStorageDefinitions($entity_type_id, $this->entityFieldManager->getFieldStorageDefinitions($entity_type_id));
}
$this->eventDispatcher->dispatch(EntityTypeEvents::CREATE, new EntityTypeEvent($entity_type));
$this->eventDispatcher->dispatch(new EntityTypeEvent($entity_type), EntityTypeEvents::CREATE);
$this->clearCachedDefinitions();
}
......@@ -98,7 +98,7 @@ public function onFieldableEntityTypeCreate(EntityTypeInterface $entity_type, ar
$this->entityLastInstalledSchemaRepository->setLastInstalledFieldStorageDefinitions($entity_type_id, $field_storage_definitions);
}
$this->eventDispatcher->dispatch(EntityTypeEvents::CREATE, new EntityTypeEvent($entity_type));
$this->eventDispatcher->dispatch(new EntityTypeEvent($entity_type), EntityTypeEvents::CREATE);
$this->clearCachedDefinitions();
}
......@@ -119,7 +119,7 @@ public function onEntityTypeUpdate(EntityTypeInterface $entity_type, EntityTypeI
$this->entityLastInstalledSchemaRepository->setLastInstalledDefinition($entity_type);
$this->eventDispatcher->dispatch(EntityTypeEvents::UPDATE, new EntityTypeEvent($entity_type, $original));
$this->eventDispatcher->dispatch(new EntityTypeEvent($entity_type, $original), EntityTypeEvents::UPDATE);
$this->clearCachedDefinitions();
}
......@@ -142,7 +142,7 @@ public function onEntityTypeDelete(EntityTypeInterface $entity_type) {
$this->entityLastInstalledSchemaRepository->deleteLastInstalledDefinition($entity_type_id);
$this->eventDispatcher->dispatch(EntityTypeEvents::DELETE, new EntityTypeEvent($entity_type));
$this->eventDispatcher->dispatch(new EntityTypeEvent($entity_type), EntityTypeEvents::DELETE);
$this->clearCachedDefinitions();
}
......@@ -165,7 +165,7 @@ public function onFieldableEntityTypeUpdate(EntityTypeInterface $entity_type, En
$this->entityLastInstalledSchemaRepository->setLastInstalledFieldStorageDefinitions($entity_type_id, $field_storage_definitions);
}
$this->eventDispatcher->dispatch(EntityTypeEvents::UPDATE, new EntityTypeEvent($entity_type, $original));
$this->eventDispatcher->dispatch(new EntityTypeEvent($entity_type, $original), EntityTypeEvents::UPDATE);
$this->clearCachedDefinitions();
}
}
......
......@@ -87,7 +87,7 @@ public function onFieldStorageDefinitionCreate(FieldStorageDefinitionInterface $
$this->entityLastInstalledSchemaRepository->setLastInstalledFieldStorageDefinition($storage_definition);
$this->eventDispatcher->dispatch(FieldStorageDefinitionEvents::CREATE, new FieldStorageDefinitionEvent($storage_definition));
$this->eventDispatcher->dispatch(new FieldStorageDefinitionEvent($storage_definition), FieldStorageDefinitionEvents::CREATE);
$this->entityFieldManager->clearCachedFieldDefinitions();
}
......@@ -106,7 +106,7 @@ public function onFieldStorageDefinitionUpdate(FieldStorageDefinitionInterface $
$this->entityLastInstalledSchemaRepository->setLastInstalledFieldStorageDefinition($storage_definition);
$this->eventDispatcher->dispatch(FieldStorageDefinitionEvents::UPDATE, new FieldStorageDefinitionEvent($storage_definition, $original));
$this->eventDispatcher->dispatch(new FieldStorageDefinitionEvent($storage_definition, $original), FieldStorageDefinitionEvents::UPDATE);
$this->entityFieldManager->clearCachedFieldDefinitions();
}
......@@ -135,7 +135,7 @@ public function onFieldStorageDefinitionDelete(FieldStorageDefinitionInterface $
$this->entityLastInstalledSchemaRepository->deleteLastInstalledFieldStorageDefinition($storage_definition);
$this->eventDispatcher->dispatch(FieldStorageDefinitionEvents::DELETE, new FieldStorageDefinitionEvent($storage_definition));
$this->eventDispatcher->dispatch(new FieldStorageDefinitionEvent($storage_definition), FieldStorageDefinitionEvents::DELETE);
$this->entityFieldManager->clearCachedFieldDefinitions();
}
......
......@@ -206,7 +206,7 @@ protected function prepare(array $main_content, Request $request, RouteMatchInte
// Select the page display variant to be used to render this main content,
// default to the built-in "simple page".
$event = new PageDisplayVariantSelectionEvent('simple_page', $route_match);
$this->eventDispatcher->dispatch(RenderEvents::SELECT_PAGE_DISPLAY_VARIANT, $event);
$this->eventDispatcher->dispatch($event, RenderEvents::SELECT_PAGE_DISPLAY_VARIANT);
$variant_id = $event->getPluginId();
// We must render the main content now already, because it might provide a
......
......@@ -181,12 +181,12 @@ public function rebuild() {
// DYNAMIC is supposed to be used to add new routes based upon all the
// static defined ones.
$this->dispatcher->dispatch(RoutingEvents::DYNAMIC, new RouteBuildEvent($collection));
$this->dispatcher->dispatch(new RouteBuildEvent($collection), RoutingEvents::DYNAMIC);
// ALTER is the final step to alter all the existing routes. We cannot stop
// people from adding new routes here, but we define two separate steps to
// make it clear.
$this->dispatcher->dispatch(RoutingEvents::ALTER, new RouteBuildEvent($collection));
$this->dispatcher->dispatch(new RouteBuildEvent($collection), RoutingEvents::ALTER);
$this->checkProvider->setChecks($collection);
......@@ -194,7 +194,7 @@ public function rebuild() {
$this->dumper->dump();
$this->lock->release('router_rebuild');
$this->dispatcher->dispatch(RoutingEvents::FINISHED, new Event());
$this->dispatcher->dispatch(new Event(), RoutingEvents::FINISHED);
$this->building = FALSE;
$this->rebuildNeeded = FALSE;
......
......@@ -62,7 +62,7 @@ public function setAccount(AccountInterface $account) {
}
$this->account = $account;
$this->id = $account->id();
$this->eventDispatcher->dispatch(AccountEvents::SET_USER, new AccountSetEvent($account));
$this->eventDispatcher->dispatch(new AccountSetEvent($account), AccountEvents::SET_USER);
}
/**
......
......@@ -649,7 +649,7 @@ protected function filterResponse(Request $request, $request_type, Response $res
assert($request_type === HttpKernelInterface::MASTER_REQUEST || $request_type === HttpKernelInterface::SUB_REQUEST);
$this->requestStack->push($request);
$event = new ResponseEvent($this->httpKernel, $request, $request_type, $response);
$this->eventDispatcher->dispatch(KernelEvents::RESPONSE, $event);
$this->eventDispatcher->dispatch($event, KernelEvents::RESPONSE);
$filtered_response = $event->getResponse();
$this->requestStack->pop();
return $filtered_response;
......
......@@ -73,7 +73,7 @@ protected function checkAccess(EntityInterface $entity, $operation, AccountInter
if (empty($dependency)) {
// If an access dependency has not been set let modules set one.
$event = new BlockContentGetDependencyEvent($entity);
$this->eventDispatcher->dispatch(BlockContentEvents::BLOCK_CONTENT_GET_DEPENDENCY, $event);
$this->eventDispatcher->dispatch($event, BlockContentEvents::BLOCK_CONTENT_GET_DEPENDENCY);
$dependency = $event->getAccessDependency();
if (empty($dependency)) {
return AccessResult::forbidden("Non-reusable blocks must set an access dependency for access control.");
......
......@@ -384,7 +384,7 @@ public function populateFromRouteMatch(RouteMatchInterface $route_match) {
$this->langcode = $route_match->getParameter('langcode');
$event = new ConfigMapperPopulateEvent($this, $route_match);
$this->eventDispatcher->dispatch(ConfigTranslationEvents::POPULATE_MAPPER, $event);
$this->eventDispatcher->dispatch($event, ConfigTranslationEvents::POPULATE_MAPPER);
}
/**
......
......@@ -154,7 +154,7 @@ protected function createResourceType(EntityTypeInterface $entity_type, $bundle)
$fields = static::getFields($raw_fields, $entity_type, $bundle);
if (!$internalize_resource_type) {
$event = ResourceTypeBuildEvent::createFromEntityTypeAndBundle($entity_type, $bundle, $fields);
$this->eventDispatcher->dispatch(ResourceTypeBuildEvents::BUILD, $event);
$this->eventDispatcher->dispatch($event, ResourceTypeBuildEvents::BUILD);
$internalize_resource_type = $event->resourceTypeShouldBeDisabled();
$fields = $event->getFields();
}
......
......@@ -62,7 +62,7 @@ public function save($has_trusted_data = FALSE) {
// an update of configuration, but only for a specific language.
Cache::invalidateTags($this->getCacheTags());
$this->isNew = FALSE;
$this->eventDispatcher->dispatch(LanguageConfigOverrideEvents::SAVE_OVERRIDE, new LanguageConfigOverrideCrudEvent($this));
$this->eventDispatcher->dispatch(new LanguageConfigOverrideCrudEvent($this), LanguageConfigOverrideEvents::SAVE_OVERRIDE);
$this->originalData = $this->data;
return $this;
}
......@@ -75,7 +75,7 @@ public function delete() {
$this->storage->delete($this->name);
Cache::invalidateTags($this->getCacheTags());
$this->isNew = TRUE;
$this->eventDispatcher->dispatch(LanguageConfigOverrideEvents::DELETE_OVERRIDE, new LanguageConfigOverrideCrudEvent($this));
$this->eventDispatcher->dispatch(new LanguageConfigOverrideCrudEvent($this), LanguageConfigOverrideEvents::DELETE_OVERRIDE);
$this->originalData = $this->data;
return $this;
}
......
......@@ -87,7 +87,7 @@ public function __construct($uuid, $region, array $configuration = [], array $ad
*/
public function toRenderArray(array $contexts = [], $in_preview = FALSE) {
$event = new SectionComponentBuildRenderArrayEvent($this, $contexts, $in_preview);
$this->eventDispatcher()->dispatch(LayoutBuilderEvents::SECTION_COMPONENT_BUILD_RENDER_ARRAY, $event);
$this->eventDispatcher()->dispatch($event, LayoutBuilderEvents::SECTION_COMPONENT_BUILD_RENDER_ARRAY);
$output = $event->getBuild();
$event->getCacheableMetadata()->applyTo($output);
return $output;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment