diff --git a/composer.json b/composer.json index 95b3153..4e578e7 100644 --- a/composer.json +++ b/composer.json @@ -29,6 +29,11 @@ "phpunit/phpunit": "^9.0 | ^10.0", "squizlabs/php_codesniffer": "^3.0" }, + "autoload": { + "psr-4": { + "SimpleSAML\\Module\\drupalauth\\": "src/" + } + }, "autoload-dev": { "classmap": ["src/", "tests/"] }, diff --git a/src/DrupalHelper.php b/src/DrupalHelper.php index 8488c55..460d43b 100644 --- a/src/DrupalHelper.php +++ b/src/DrupalHelper.php @@ -3,6 +3,7 @@ namespace SimpleSAML\Module\drupalauth; use Drupal\Core\DrupalKernel; +use SimpleSAML\Module\drupalauth\Event\SetAttributesEvent; use Symfony\Component\HttpFoundation\Request; class DrupalHelper @@ -38,7 +39,7 @@ public function getAttributes($drupaluser, $requested_attributes): array $forbiddenAttributes = $this->forbiddenAttributes; if (empty($requested_attributes)) { - return $this->getAllAttributes($drupaluser, $forbiddenAttributes); + $attributes = $this->getAllAttributes($drupaluser, $forbiddenAttributes); } else { foreach ($requested_attributes as $attribute) { $field_name = $attribute['field_name']; @@ -78,7 +79,10 @@ public function getAttributes($drupaluser, $requested_attributes): array } } } - + $event = new SetAttributesEvent($this, $drupaluser, $requested_attributes, $attributes); + $event_dispatcher = \Drupal::service('event_dispatcher'); + $event_dispatcher->dispatch($event, SetAttributesEvent::EVENT_NAME); + $attributes = $event->getAttributes(); return $attributes; } @@ -116,7 +120,7 @@ protected function getAllAttributes($drupaluser, $forbiddenAttributes): array return $attributes; } - protected function getPropertyName($attribute_definition) + public function getPropertyName($attribute_definition) { $property_name = 'value'; if (!empty($attribute_definition['field_property'])) { @@ -126,7 +130,7 @@ protected function getPropertyName($attribute_definition) return $property_name; } - protected function getAttributeName($attribute_definition) + public function getAttributeName($attribute_definition) { if (!empty($attribute_definition['attribute_name'])) { return $attribute_definition['attribute_name']; diff --git a/src/Event/SetAttributesEvent.php b/src/Event/SetAttributesEvent.php new file mode 100644 index 0000000..6a1077e --- /dev/null +++ b/src/Event/SetAttributesEvent.php @@ -0,0 +1,71 @@ +drupalHelper; + } + + /** + * Get the requested attributes. + */ + public function getRequestedAttributes(): array + { + return $this->requestedAttributes; + } + + /** + * Get user who logged in. + */ + public function getUser(): UserInterface + { + return $this->user; + } + + /** + * Get the attributes set. + */ + public function getAttributes(): array + { + return $this->attributes; + } + + /** + * Set the attributes. + */ + public function setAttributes(array $attributes) + { + $this->attributes = $attributes; + } +}