diff --git a/src/FormField/RegisteredMFAMethodListField.php b/src/FormField/RegisteredMFAMethodListField.php index 65dc4d3..542e529 100644 --- a/src/FormField/RegisteredMFAMethodListField.php +++ b/src/FormField/RegisteredMFAMethodListField.php @@ -16,6 +16,11 @@ class RegisteredMFAMethodListField extends FormField { + /** + * @var Member + */ + private $member; + /** * {@inheritDoc} * @@ -44,13 +49,13 @@ public function getSchemaDataDefaults() $generator = SchemaGenerator::create(); if (!$this->value && $this->getForm() && $this->getForm()->getRecord() instanceof Member) { - $member = $this->getForm()->getRecord(); + $this->member = $this->getForm()->getRecord(); } else { - $member = DataObject::get_by_id(Member::class, $this->value); + $this->member = DataObject::get_by_id(Member::class, $this->value); } return array_merge($defaults, [ - 'schema' => $generator->getSchema($member) + [ + 'schema' => $generator->getSchema($this->member) + [ 'endpoints' => [ 'register' => $adminController->Link('register/{urlSegment}'), 'remove' => $adminController->Link('method/{urlSegment}'), @@ -58,7 +63,7 @@ public function getSchemaDataDefaults() ], // We need all available methods so we can re-register pre-existing methods 'allAvailableMethods' => $generator->getAvailableMethods(), - 'backupCreationDate' => $this->getBackupMethod() + 'backupCreatedDate' => $this->getBackupMethod() ? $this->getBackupMethod()->Created : null, 'resetEndpoint' => SecurityAdmin::singleton()->Link("users/reset/{$this->value}"), @@ -75,6 +80,9 @@ public function getSchemaDataDefaults() protected function getBackupMethod(): ?RegisteredMethod { $backupMethod = MethodRegistry::singleton()->getBackupMethod(); - return RegisteredMethodManager::singleton()->getFromMember(Security::getCurrentUser(), $backupMethod); + return RegisteredMethodManager::singleton()->getFromMember( + $this->member ?? Security::getCurrentUser(), + $backupMethod + ); } }