-
Notifications
You must be signed in to change notification settings - Fork 70
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
VACMS-16882: Resolves Error: Call to a member function getValue() on null #16900
Changes from 2 commits
b63e7fd
5688294
746d65e
60f4700
514fd80
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,10 +46,11 @@ public function addToNationalOutreachCalendar(EventInterface $node): void { | |
if ($node->hasField(EventOutreachInterface::LISTING_FIELD) && | ||
$node->hasField(EventOutreachInterface::PUBLISH_TO_OUTREACH_CAL_FIELD) && | ||
$node->hasField(EventOutreachInterface::ADDITIONAL_LISTING_FIELD)) { | ||
$addToCalValue = $node->get(EventOutreachInterface::PUBLISH_TO_OUTREACH_CAL_FIELD)->first()->getValue(); | ||
if (isset($addToCalValue['value'])) { | ||
if ($node->get(EventOutreachInterface::PUBLISH_TO_OUTREACH_CAL_FIELD)->first()) { | ||
$addToCalValue = $node->get(EventOutreachInterface::PUBLISH_TO_OUTREACH_CAL_FIELD)->first()->getValue(); | ||
$listings = $node->get(EventOutreachInterface::LISTING_FIELD)->getValue(); | ||
$additionalListings = $node->get(EventOutreachInterface::ADDITIONAL_LISTING_FIELD)->getValue(); | ||
assert(array_key_exists('value', $addToCalValue)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am pretty sure I am missing the use case/edge case here so apologies for the potentially dumb question here. Is there an edge case where it would get past line 49 and still not have a 'value' here at line 53? If there is, it might be good to spell out with a comment the situation that would lead to the assertion failing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good question Steve. My thinking in this case was that there is actually no guarantee that, even though the field has a value, that the property 'value' exists in the returned array. For entity reference fields for example, the primary field property is 'target_id'. So this assertion was a way for me to protect against any future changes to the target field where it changes to a different type, or for some reason the 'value' property changes to something else. Generally I've been trying to get away from using magic methods to get to field values, which would actually improve the readability of this code, but this is the outcome of doing that in this situation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense. Thanks for the explanation @dsasser. |
||
if ($addToCalValue['value'] === 1 || $this->outreachHubOnlyUser()) { | ||
// Add to Outreach calendar selected, or user is Outreach Hub only | ||
// user. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a good combination to defend against NULL.