Problem/Motivation

Getting an undefined index on any new taxonomy field i add to a content type

Notice: Undefined index: target_id in Drupal\permissions_by_term\Service\TermHandler->getTidsByNid() (line 68 of modules/contrib/permissions_by_term/src/Service/TermHandler.php).

Drupal\permissions_by_term\Service\TermHandler->getTidsByNid('33') (Line: 72)

Steps to reproduce

* PHP 7.4, Drupal 9.1.2
* Add an existing taxonomy reference field to a content type, for instance: field_tags
* Create node
* Editing the node gives the notice

Proposed resolution

Add a check to see if the term's target_id key is actually in the "termTargetIdsForField" array. See attached patch.

Comments

j0sbeir created an issue. See original summary.

j0sbeir’s picture

Title: Undefined index 'target_id' » Undefined index 'target_id' in Drupal\permissions_by_term\Service\TermHandler->getTidsByNid()
aritrika.d’s picture

StatusFileSize
new577 bytes
bdanin’s picture

This patch appears to have worked well for me. Thanks.

nattyweb’s picture

I have this same issue with Drupal 8.9.12 and Permissions by Term 8.x-2.28. Would this same patch work there?
Thanks
Martin

bdanin’s picture

@nattyweb, this is the same setup I'm running (currently on 8.9.11, but would assume 8.9.12 is the same) and the patch appears to be working. I haven't tested it extensively, but let us know if it works for you, and if so, then we can probably set this as RTBC.

nattyweb’s picture

I can confirm this did indeed fix the problem on Drupal 8.9.12 and Permissions by Term 8.x-2.28.
I checked before applying to make sure the code looked the same at the relevant place in /src/Service/TermHandler.php, which it did.
Thank you!

bdanin’s picture

Status: Active » Reviewed & tested by the community

jepster_’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for sharing your patch!

It has been applied to PbT version 8.x-2.29 and 3.1.6.

jepster_’s picture

Status: Fixed » Closed (fixed)