diff --git a/Civi/RemoteTools/ActionHandler/AbstractProfileEntityActionsHandler.php b/Civi/RemoteTools/ActionHandler/AbstractProfileEntityActionsHandler.php index e3f957a..685b462 100644 --- a/Civi/RemoteTools/ActionHandler/AbstractProfileEntityActionsHandler.php +++ b/Civi/RemoteTools/ActionHandler/AbstractProfileEntityActionsHandler.php @@ -348,7 +348,7 @@ protected function getEntityById(int $id, string $actionName, ?int $contactId): protected function getEntityFieldsForFormSpec(?int $contactId, array $values = []): array { /** @phpstan-var array> $fields */ $fields = $this->api4->execute($this->profile->getEntityName(), 'getFields', [ - 'loadOptions' => $this->profile->isFormSpecNeedsFieldOptions(), + 'loadOptions' => $this->profile->getFieldLoadOptionsForFormSpec(), 'values' => $values, 'checkPermissions' => $this->profile->isCheckApiPermissions($contactId), ])->indexBy('name')->getArrayCopy(); diff --git a/Civi/RemoteTools/EntityProfile/AbstractRemoteEntityProfile.php b/Civi/RemoteTools/EntityProfile/AbstractRemoteEntityProfile.php index 401b108..e43cd67 100644 --- a/Civi/RemoteTools/EntityProfile/AbstractRemoteEntityProfile.php +++ b/Civi/RemoteTools/EntityProfile/AbstractRemoteEntityProfile.php @@ -84,7 +84,7 @@ public function convertToRemoteValues(array $entityValues, array $select, ?int $ /** * @inheritDoc */ - public function isFormSpecNeedsFieldOptions(): bool { + public function getFieldLoadOptionsForFormSpec() { return FALSE; } diff --git a/Civi/RemoteTools/EntityProfile/AbstractRemoteEntityProfileDecorator.php b/Civi/RemoteTools/EntityProfile/AbstractRemoteEntityProfileDecorator.php index 44fd200..c96a802 100644 --- a/Civi/RemoteTools/EntityProfile/AbstractRemoteEntityProfileDecorator.php +++ b/Civi/RemoteTools/EntityProfile/AbstractRemoteEntityProfileDecorator.php @@ -127,8 +127,8 @@ public function getUpdateFormSpec(array $entityValues, array $entityFields, ?int /** * @inheritDoc */ - public function isFormSpecNeedsFieldOptions(): bool { - return $this->profile->isFormSpecNeedsFieldOptions(); + public function getFieldLoadOptionsForFormSpec() { + return $this->profile->getFieldLoadOptionsForFormSpec(); } /** diff --git a/Civi/RemoteTools/EntityProfile/ReadOnlyRemoteEntityProfile.php b/Civi/RemoteTools/EntityProfile/ReadOnlyRemoteEntityProfile.php index adcf6aa..a13b111 100644 --- a/Civi/RemoteTools/EntityProfile/ReadOnlyRemoteEntityProfile.php +++ b/Civi/RemoteTools/EntityProfile/ReadOnlyRemoteEntityProfile.php @@ -132,7 +132,7 @@ public function getUpdateFormSpec(array $entityValues, array $entityFields, ?int /** * @inheritDoc */ - public function isFormSpecNeedsFieldOptions(): bool { + public function getFieldLoadOptionsForFormSpec() { return FALSE; } diff --git a/Civi/RemoteTools/EntityProfile/RemoteEntityProfileInterface.php b/Civi/RemoteTools/EntityProfile/RemoteEntityProfileInterface.php index be1f436..b756797 100644 --- a/Civi/RemoteTools/EntityProfile/RemoteEntityProfileInterface.php +++ b/Civi/RemoteTools/EntityProfile/RemoteEntityProfileInterface.php @@ -152,7 +152,7 @@ public function convertToRemoteValues(array $entityValues, array $select, ?int $ * @phpstan-param array> $entityFields * Entity fields indexed by name. * - * @see isFormSpecNeedsFieldOptions + * @see getFieldLoadOptionsForFormSpec */ public function getCreateFormSpec(array $arguments, array $entityFields, ?int $contactId): FormSpec; @@ -162,18 +162,21 @@ public function getCreateFormSpec(array $arguments, array $entityFields, ?int $c * @phpstan-param array> $entityFields * Entity fields indexed by name. * - * @see isFormSpecNeedsFieldOptions + * @see getFieldLoadOptionsForFormSpec */ public function getUpdateFormSpec(array $entityValues, array $entityFields, ?int $contactId): FormSpec; /** - * @return bool - * TRUE if the options for an entity field are required to create form spec. + * @phpstan-return bool|array + * Value for the 'loadOptions' parameter when fetching entity fields that + * are passed to the form spec creation methods. FALSE if no options are + * required, TRUE to get options as id-label-pairs, or an array of the + * required option properties. * * @see getCreateFormSpec * @see getUpdateFormSpec */ - public function isFormSpecNeedsFieldOptions(): bool; + public function getFieldLoadOptionsForFormSpec(); /** * @phpstan-param array $arguments diff --git a/tests/phpunit/Civi/RemoteTools/ActionHandler/AbstractProfileEntityActionsHandlerTest.php b/tests/phpunit/Civi/RemoteTools/ActionHandler/AbstractProfileEntityActionsHandlerTest.php index 7f31a8b..0a443bb 100644 --- a/tests/phpunit/Civi/RemoteTools/ActionHandler/AbstractProfileEntityActionsHandlerTest.php +++ b/tests/phpunit/Civi/RemoteTools/ActionHandler/AbstractProfileEntityActionsHandlerTest.php @@ -134,7 +134,7 @@ public function testGetCreateForm(): void { $this->profileMock->method('isCreateGranted') ->with($arguments, self::RESOLVED_CONTACT_ID) ->willReturn(GrantResult::newPermitted()); - $this->profileMock->method('isFormSpecNeedsFieldOptions')->willReturn(TRUE); + $this->profileMock->method('getFieldLoadOptionsForFormSpec')->willReturn(TRUE); $entityFields = [ 'foo' => ['name' => 'foo'], @@ -168,7 +168,7 @@ public function testGetCreateFormDeiniedWithForm(): void { $this->profileMock->method('isCreateGranted') ->with($arguments, self::RESOLVED_CONTACT_ID) ->willReturn(GrantResult::newDeniedWithForm()); - $this->profileMock->method('isFormSpecNeedsFieldOptions')->willReturn(FALSE); + $this->profileMock->method('getFieldLoadOptionsForFormSpec')->willReturn(FALSE); $entityFields = [ 'foo' => ['name' => 'foo'], @@ -219,7 +219,7 @@ public function testValidateCreateForm(): void { $this->profileMock->method('isCreateGranted') ->with($arguments, self::RESOLVED_CONTACT_ID) ->willReturn(GrantResult::newPermitted()); - $this->profileMock->method('isFormSpecNeedsFieldOptions')->willReturn(TRUE); + $this->profileMock->method('getFieldLoadOptionsForFormSpec')->willReturn(TRUE); $entityFields = [ 'foo' => ['name' => 'foo'], @@ -272,7 +272,7 @@ public function testGetUpdateForm(): void { $this->profileMock->method('isUpdateGranted') ->with($entityValues, self::RESOLVED_CONTACT_ID) ->willReturn(GrantResult::newPermitted()); - $this->profileMock->method('isFormSpecNeedsFieldOptions')->willReturn(FALSE); + $this->profileMock->method('getFieldLoadOptionsForFormSpec')->willReturn(FALSE); $valueMap = [ [ @@ -327,7 +327,7 @@ public function testGetUpdateFormDeniedWithForm(): void { $this->profileMock->method('isUpdateGranted') ->with($entityValues, self::RESOLVED_CONTACT_ID) ->willReturn(GrantResult::newDeniedWithForm()); - $this->profileMock->method('isFormSpecNeedsFieldOptions')->willReturn(TRUE); + $this->profileMock->method('getFieldLoadOptionsForFormSpec')->willReturn(TRUE); $valueMap = [ [