🇫🇷France @blink38

Account created on 12 March 2015, about 10 years ago
#

Recent comments

🇫🇷France blink38

This patch seems correct. I wrote the same code in my own custom module I needed for another module displaying block in profile page.

I have no idea on how to help writing test classes.

I'm using the following code based on PHP attributes to use the context in my BlockBase.

#[Block(
    id: "custom_user_block",
    admin_label: new TranslatableMarkup("Custom user block"),
    context_definitions: [
        "profile" => new EntityContextDefinition(
            data_type: 'entity:profile',
            label: 'Profile Context',
            required: FALSE
        )
    ]
)]

And in the build() :

$profile = $this->getContextValue('profile');

if ($profile->hasField('field_name')){
     $value = $profile->get('field_name')->value;
     ...
}
Production build 0.71.5 2024