Problem/Motivation
I'm using the custom_value processor on my site. I just saw that if you forgot to set a value on a custom_value field in your index, it throws a warning error :
Warning : Undefined variable $field_value dans Drupal\search_api\Plugin\search_api\processor\CustomValue->addFieldValues() (/home/tmaquin/Bureau/drupalfactory/web/modules/contrib/search_api/src/Plugin/search_api/processor/CustomValue.php ligne 118)
I think this processor shouldn't throw errors even if you misconfigured your custom fields.
Proposed resolution
Could we juste replace in CustomValue the iteration by a empty function ?
if (!empty($field_value)) { $field->addValue($field_value); }
Instead of
if ($field_value !== '') { $field->addValue($field_value); }
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | 3406283-2--custom_value_processor_value_wo_tokens.patch | 2.53 KB | drunken monkey |
| #2 | 3406283-2--custom_value_processor_value_wo_tokens--tests_only.patch | 1.64 KB | drunken monkey |
Comments
Comment #2
drunken monkeyThanks a lot for reporting this problem!
It’s actually even more serious: it seems the problem is not with missing values (those are handled fine), but with values that don’t contain any tokens. Can you confirm that a field like that is present in your index?
(Seems like I was pretty sloppy in reviewing once again, the IDE even displays a warning that the variable might be undefined.)
Anyways, the attached patches both demonstrate the problem (with a regression test) and provide a solution. Please test/review!
Comment #4
t.maquin commentedThanks for your response !
Your patch does the work and yes, i needed to have two custom fields on my index that does not contain any tokens.
I handle theses fields with a custom processor to set specific values in it.
Your patch should be applied to the contrib.
Comment #5
t.maquin commentedComment #7
drunken monkeyThanks a lot for reporting back, good to hear it worked.
Merged. Thanks again!