- Issue created by @Summit
- ๐ฎ๐ณIndia chetan 11
chetan 11 โ made their first commit to this issueโs fork.
- Status changed to Needs review
12 months ago 9:49am 7 December 2023 - ๐ฎ๐ณIndia chetan 11
Hi,
I have fixed the above error on "custom formatter's module, please check the raised MR.
Thanks. - Status changed to RTBC
11 months ago 4:28pm 19 December 2023 - ๐ณ๐ฑNetherlands Summit
Hi, when will this patch be committed please? I ask it so whether i have to change my composer.json, or can wait for the new .dev version?
Greetings and a happy 2024! - ๐ณ๐ฑNetherlands Summit
Hi, I thought the patch worked, but now under Drupal 10.3 with custom formatters, and adding https://git.drupalcode.org/project/custom_formatters/-/merge_requests/4.... to my composer.json
the warning is:Warning: Trying to access array offset on value of type null in eval() (regel 2 van custom_formatters/src/Plugin/CustomFormatters/FormatterType/PHP.php(46)
Greetings, Martijn
- Status changed to Active
4 months ago 1:33pm 20 July 2024 - ๐ณ๐ฑNetherlands Summit
Hi, could it be related to https://www.drupal.org/project/custom_formatters/issues/3404747 ๐ Does not work with drupal 10 Needs review ?
I did add this patch...and still got these warnings back going to drupal 10.3.1
thanks for your reply in advance,
greetings, - ๐ณ๐ฑNetherlands Summit
Hi,
I use custom formatters in relation to shurly. Latest Beta4 version Shurly.
Could that have something to do with my problem of these warnings?
This is my Custom Formatters code, for the field Link:$shorturl = $items->getValue()[0]['uri']; $shortitem = shurly_shorten($items->getValue()[0]['uri']); if (isset($shortitem['shortUrl'])) { $shorturl = $shortitem['shortUrl']; } $output = '<a href="' . $shorturl . '" class="btn btn-primary" rel="nofollow" target="_blank"> Shortlink text </a>'; return $output;
Greetings,
- ๐ณ๐ฑNetherlands Summit
Hi,
could this be a temperal solution to get rid of the warning?if (isset($data)) { $output = eval($data); }
The complete changed code looks than like this:
public function viewElements(FieldItemListInterface $items, $langcode) { ob_start(); $data = $this->entity->get('data'); if (is_array($data) && isset($data[0])) { $output = eval($data[0]); } else { if (isset($data)) { $output = eval($data); } } $output = !empty($output) ? $output : ob_get_contents(); ob_end_clean(); return empty($output) ? FALSE : $output; }
It seems that the warning is gone with this change.
Greetings, - Status changed to Needs work
4 months ago 3:44pm 28 July 2024 - ๐ณ๐ฑNetherlands Summit
Hi,
And I also read, using eval() is not good practice, see: https://www.exakat.io/en/land-where-php-uses-eval/
Sorry if I am wrong, I am not a programmer.
greetings, - Status changed to Closed: works as designed
4 months ago 8:08am 30 July 2024 - ๐ณ๐ฑNetherlands Summit
Hi,
It was indeed a failure on my part. Some custom formatters nodes got value, other not. The one without kicked in the warning!
This did the trick with me:if ($items->getValue() && isset($items->getValue()[0]['uri'])) { $shorturl = $items->getValue()[0]['uri']; $shortitem = shurly_shorten($items->getValue()[0]['uri']); if (isset($shortitem['shortUrl'])) { $shorturl = $shortitem['shortUrl']; } $output = '<a href="' . $shorturl . '" class="btn btn-primary" rel="nofollow" target="_blank"> โค Actuele Tarieven e/o Boeken ! </a>'; return $output; }
Greetings,