-
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
VACMS-16882: Resolves Error: Call to a member function getValue() on null #16900
Conversation
GitHub Workflows (.github/workflows/*.yml)Have you...
|
Rebuilding because of Tugboat antics. |
va/tests/status-error:
|
…ember-function-on-null-in-addToNationalOutreachCalendar
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.
…in-addToNationalOutreachCalendar
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.
Worked as expected. No errors! Nice work!!
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.
Just one question from me.
$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(); |
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.
$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 comment
The 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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. Thanks for the explanation @dsasser.
Description
Resolves a bug in addToNationalOutreachCalendar() which can cause a php error.
Relates to #16882
Testing done
Tested using different user roles, and using new and existing Event nodes.
QA steps
As a content admin
Definition of Done
Select Team for PR review
CMS Team
Public websites
Facilities
User support
Accelerated Publishing