Skip to content

Commit

Permalink
RemoteEntityProfileInterface: Rename isFormSpecNeedsFieldOptions()
Browse files Browse the repository at this point in the history
…to `getFieldLoadOptionsForFormSpec()` and allow to return an array of strings
  • Loading branch information
Dominic Tubach committed Oct 27, 2023
1 parent 3abf121 commit 79ac101
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ protected function getEntityById(int $id, string $actionName, ?int $contactId):
protected function getEntityFieldsForFormSpec(?int $contactId, array $values = []): array {
/** @phpstan-var array<string, array<string, mixed>> $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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function convertToRemoteValues(array $entityValues, array $select, ?int $
/**
* @inheritDoc
*/
public function isFormSpecNeedsFieldOptions(): bool {
public function getFieldLoadOptionsForFormSpec() {
return FALSE;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function getUpdateFormSpec(array $entityValues, array $entityFields, ?int
/**
* @inheritDoc
*/
public function isFormSpecNeedsFieldOptions(): bool {
public function getFieldLoadOptionsForFormSpec() {
return FALSE;
}

Expand Down
13 changes: 8 additions & 5 deletions Civi/RemoteTools/EntityProfile/RemoteEntityProfileInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public function convertToRemoteValues(array $entityValues, array $select, ?int $
* @phpstan-param array<string, array<string, mixed>> $entityFields
* Entity fields indexed by name.
*
* @see isFormSpecNeedsFieldOptions
* @see getFieldLoadOptionsForFormSpec
*/
public function getCreateFormSpec(array $arguments, array $entityFields, ?int $contactId): FormSpec;

Expand All @@ -162,18 +162,21 @@ public function getCreateFormSpec(array $arguments, array $entityFields, ?int $c
* @phpstan-param array<string, array<string, mixed>> $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<string>
* 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<int|string, mixed> $arguments
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down Expand Up @@ -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'],
Expand Down Expand Up @@ -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'],
Expand Down Expand Up @@ -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 = [
[
Expand Down Expand Up @@ -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 = [
[
Expand Down

0 comments on commit 79ac101

Please sign in to comment.