- Issue created by @littlepixiez
- @littlepixiez opened merge request.
- Assigned to littlepixiez
- Status changed to Needs work
about 2 years ago 12:44pm 2 February 2023 - 🇬🇧United Kingdom littlepixiez
I need to add tests for this, but I've done the initial commit that provides the context provider.
- 🇫🇷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; ... }