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

[BUG] NodeHasParent code throws error if runs on any new content type with Entity Reference field #2259

Closed
wgilling opened this issue Sep 12, 2023 · 2 comments
Assignees
Labels
Type: bug identifies a problem in the software with clear steps to reproduce

Comments

@wgilling
Copy link
Contributor

Islandora code can break drupal site when a new content type has an entity reference field.

The offending code is here and can be fixed in a couple different ways:

  protected function evaluateEntity(EntityInterface $entity) {
    foreach ($entity->referencedEntities() as $referenced_entity) {
      if ($entity->getEntityTypeID() == 'node' && $referenced_entity->getEntityTypeId() == 'node') {
        $parent_reference_field = $this->configuration['parent_reference_field'];
        $field = $entity->get($parent_reference_field);

The easiest way to fix this is to check that the referenced nodes are bundle() = islandora_object. Another approach would be to check $entity hasField($parent_reference_field) before trying to get it. This change does the trick nicely.
if ($entity->getEntityTypeID() == 'node' && $entity->bundle() == 'islandora_object' && $referenced_entity->getEntityTypeId() == 'node') {

What steps does it take to reproduce the issue?

  1. log in and create a new content type
  2. add a field called "nodes" which is Entity Reference type & save new content type
  3. make sure there is a context rule which has a "Node has parent" condition. If there isn't one, just add a basic rule (I believe that Islandora comes with such a context rule already configured)
  4. now, create a node of this type -- add at least one entity to the "nodes" field and save. The error occurs when this new node is now edited.
  • When does this issue occur?
    When Islandora code runs through possible context rules and any rule has the "Node has parent" condition.

  • Which page does it occur on?
    The error occurs on the node/{nid}/edit route for the new content type.

  • What happens?
    Because the new content type "nodes" does not have the field which is checked inside this logic (only "islandora_object" has this), there is a fatal error when trying to edit these.

  • To whom does it occur (anonymous visitor, editor, administrator)?
    User who attempts to edit the new "nodes" node.

  • What did you expect to happen?
    There should be no error.

Which version of Islandora are you using?
latest 2.x

Which method did you use to install your Islandora instance? (manually, ISLE, playbook, etc.)
ISLE

Any related open or closed issues to this bug report?
not yet

@wgilling wgilling added the Type: bug identifies a problem in the software with clear steps to reproduce label Sep 12, 2023
@wgilling
Copy link
Contributor Author

To properly address this, I should use the "hasField" method to check that the entity has the field before trying to get it. The other method is potentially bad only because the name of "islandora_object" is not guaranteed to be the same or if an organization copies that content type to extend functionality, the "hasField" would work on each of those and would never throw this error.

@wgilling
Copy link
Contributor Author

I'd close this since PR 979 above is merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: bug identifies a problem in the software with clear steps to reproduce
Projects
None yet
Development

No branches or pull requests

1 participant