Assigning an image item to an ImageField should not set alt text
Expected Behavior
Assigning an (image) item directly to a image field property should produce a raw value such as
<image mediaid="{F635CA48-769C-4034-BADE-6F1DF273EBE2}" />
Actual Behavior
If the image has an alt text, it is copied into the field value:
<image alt="Emilie" mediaid="{F635CA48-769C-4034-BADE-6F1DF273EBE2}" />
Steps to Reproduce the Problem
-
Add an "Image" field to the Sample Item template.
-
Open the home item and select the following image by browsing: "/sitecore/media library/Experience Explorer/Presets/Emilie 128x128"
-
Check raw value (no alt text)
-
Reset the Image field
-
Run the following script
$item = Get-Item /content/home
$item.Image = Get-Item "/media library/Experience Explorer/Presets/Emilie 128x128"
$item.Image
Apart from working differently from the expected Sitecore behaviour, there are a number of possible issues with this:
If the user uses Content Editor to change the image to e.g. "/sitecore/media library/Experience Explorer/Presets/Christian 128x128", the end result is the "Christian" image with the "Emilie" alt text.
Also, I imagine (but admittedly have not tested) that if the image field is shared and is assigned an image where the alt text has been translated, these translations will not be used when the image field is rendered.
@jomiham unfortunately in it's current form this would be a breaking change for existing developers.
One option for you right now would be to clear the data.
$item.Editing.BeginEdit()
$item.PSFields.Image.Alt = ''
$item.Editing.EndEdit()
@AdamNaj Thoughts?
Current behavior:
imageField.Alt = !string.IsNullOrEmpty(media.Alt) ? media.Alt : media.DisplayName;