getValue() on NULL

Created on 24 April 2025, 17 days ago

I have added this field an entity that already has instances. It's a block type called image with one image field already on it.

When I visit a page that has one of these blocks on I get the following message.

Error: Call to a member function getValue() on null in Drupal\user_selected_formatter\UserSelectedFormatterService->getPresetByTargetField() (line 42 of modules/contrib/user_selected_formatter/src/UserSelectedFormatterService.php).

I guess there is no default if the value is not set?

Cheers Dan

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇬🇧United Kingdom danharper

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @danharper
  • First commit to issue fork.
  • @priti197 opened merge request.
  • 🇮🇳India priti197 Mumbai - India

    Created MR !1 to fix the issue.

  • 🇬🇧United Kingdom danharper

    Hi,

    With the patch I still get en error but it's slightly different, when I looked at the code I noticed there is an declared $node variable in the patch too.

    Error: Call to a member function get() on null in Drupal\user_selected_formatter\UserSelectedFormatterService->getPresetByTargetField() (line 41 of modules/contrib/user_selected_formatter/src/UserSelectedFormatterService.php).
    

    It might be the context I am using this which causes the problem. I have a custom block with image field that I am using in layout builder as even with the patch if i do the following.

    1. I create a new page
    2. Switch to layout builder
    3. Add image block tjat has image field and formatters on

    The block will not save and this is in the log file,

    Error: Call to a member function get() on null in Drupal\user_selected_formatter\UserSelectedFormatterService->getPresetByTargetField() (line 41 of /app/web/modules/contrib/user_selected_formatter/src/UserSelectedFormatterService.php)
    
    Message	Warning: Undefined variable $node in Drupal\user_selected_formatter\UserSelectedFormatterService->getPresetByTargetField() (line 41 of /app/web/modules/contrib/user_selected_formatter/src/UserSelectedFormatterService.php
    

    Thanks Dan

  • 🇬🇧United Kingdom danharper
Production build 0.71.5 2024