- πΊπΈUnited States brooke_heaton
I'm updating to Drupal 10 and am now getting this error after using this patch:
PHP Fatal error: Uncaught Error: Class "Twig_Extension" not found in /app/docroot/modules/contrib/profile/src/TwigExtension/ProfileExtension.php:10 Stack trace:
- πΊπΈUnited States chucksimply
I'm using this approach for displaying profile fields on my user.html.twig template.
Create or Add this to a custom module.
function custom_mods_preprocess_user(&$variables) { $user = $variables['user']; $profile_storage = \Drupal::entityTypeManager()->getStorage('profile'); // Load 'profile type'. $business_profiles = $profile_storage->loadByProperties([ 'uid' => $user->id(), 'type' => 'business_profile', ]); if (!empty($business_profiles)) { $business_profile = reset($business_profiles); if ($business_profile->hasField('field_profile_first_name') && !$business_profile->get('field_profile_first_name')->isEmpty()) { $variables['biz_profile_first_name'] = $business_profile->get('field_profile_first_name')->value; } } }
Now you can call biz_profile_first_name in your user.html.twig template
{% if biz_profile_first_name %} {{ biz_profile_first_name }} {% endif %}
And add all subsequent fields in if statements like the above field_profile_first_name code.
Not a perfect solution, but hopefully helps some folks.