Curb attempt to iterate over NULL from getParentNidsOfFileEntity() #14
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
\Drupal\embargoes\EmbargoesEmbargoesService\getParentNidsOfFileEntity()
returns eitherNULL
or an array depending on found relationships. Both times it's being used in practice inembargoes.module
, the results are being passed togetActiveEmbargoesByNids()
, which passes them through togetCurrentEmbargoesByNids()
, which passes them through togetAllEmbargoesByNids()
, which attempts to iterate over them as an array. If the file entity doesn't have any parents, iterating overNULL
causes an error to be thrown.It's hard to tell the direction to go in here (could do a null check in the .module), but I'm thinking it's perhaps reasonable to enforce that
getParentNidsOfFileEntity()
returns an array that may be empty if there are no such node IDs or aren't accessible.