Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand event API to include partners as array string. DDFHER-119 #1743

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

rasben
Copy link
Contributor

@rasben rasben commented Nov 11, 2024

Link to issue

https://reload.atlassian.net/browse/DDFHER-119

/api/v1/events

Screenshot 2024-11-11 at 15 20 39

Copy link
Contributor

@kasperg kasperg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 but I think the handling of multivalue fields needs a some more consideration.

@@ -63,6 +63,7 @@ public function getResponse(EventInstance $event_instance): EventsGET200Response
'branches' => $this->getBranches(),
'address' => $this->getAddress(),
'tags' => $this->getTags(),
'partners' => $this->getMultiValue('event_partners'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider what happens with this value if there are no partners.

The spec requires an optional array of strings.getMultiValue() returns null or an array of strings. Will the response leave out the partners property if the value is null or automatically convert it to an empty array?

Personally I would prefer getMultiValue() to always return an array of strings. The value might then be empty.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point. I've updated it so it'll always return an array, even if it is empty.

return NULL;
}

return explode(', ', $strings);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please consider if this is an appropriate way to handle multivalue fields.

As I read it, if one of the value contain , then it will be treated as a multivalue. That does not seem right. Is there a better way to go about this?

If we go with this approach I would appreciate a reference to why , is an appropriate separator.

event_partners is a multivalue field and to me it is not obvious that multiple values are separated by , by Drupal Core/$field->getString().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was an attempt to reuse the custom getValue() method, but, i didnt consider that strings might actually contain , .
I've updated it, to use the Drupal getValue method instead, and using array_column to turn it into a simple array.

@kasperg kasperg assigned rasben and unassigned kasperg, xendk and kasperbirch1 Nov 12, 2024
Copy link
Contributor

@kasperg kasperg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 LGTM

@kasperg kasperg assigned rasben and unassigned kasperg Nov 20, 2024
@rasben rasben added the jira-testable ready for DDF test, and moved in Jira label Nov 25, 2024
@rasben rasben removed their assignment Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
jira-testable ready for DDF test, and moved in Jira
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants