function uma_ImageURL in User Menu Avatar (User Image in Menu) 8.4
Same name and namespace in other branches
- 8.5 user_menu_avatar.module \uma_ImageURL()
Set the $imageURL value.
2 calls to uma_ImageURL()
- uma_apply_markup in ./
user_menu_avatar.module - Apply markup per menu link.
- uma_Markup in ./
user_menu_avatar.module - Build our new replacement markup.
File
- ./
user_menu_avatar.module, line 113 - Display user picture and/or user name in menu.
Code
function uma_ImageURL() {
// Instantiate $imageURL to empty string.
$imageURL = '';
// Compare $showAvatar.
if (uma_CFV()['showAvatar'] == 'yes') {
// Set the avatar field name.
$imageFieldName = uma_CFV()['avatarImageField'];
// Check that the field exists.
if (!empty(FieldConfig::loadByName('user', 'user', $imageFieldName))) {
// Load image style.
$imageStyle = \Drupal::entityTypeManager()
->getStorage('image_style')
->load('thumbnail');
// Check that an image exists in the field.
if (uma_getUser()['currentUser']->{$imageFieldName}->entity) {
// Load image with image style.
$imageStyleURL = $imageStyle
->buildUrl(uma_getUser()['currentUser']->{$imageFieldName}->entity->uri->value);
// Set $imageURL as image field url value.
$imageURL = $imageStyleURL;
}
elseif (FieldConfig::loadByName('user', 'user', $imageFieldName)
->getSetting('default_image')['uuid']) {
// Load the default image settings.
$imageGetSettings = FieldConfig::loadByName('user', 'user', $imageFieldName)
->getSetting('default_image');
// Get the default image URI from settings.
$imageURI = Drupal::service('entity.repository')
->loadEntityByUuid('file', $imageGetSettings['uuid'])
->getFileUri();
// Load image with image style.
$imageStyleURL = $imageStyle
->buildUrl($imageURI);
// Set $imageURL as image field default URI value.
$imageURL = $imageStyleURL;
}
}
}
return file_url_transform_relative($imageURL);
}