Score:0

How to determine entity where image field is housed?

id flag

I need to check if an image media field is housed in a paragraph to remove the alt attribute of that attribute. The same image field could be referenced anywhere. I could remove the alt field it within preprocess_image by checking if the value is set to a particular value.

However I need a more robust method by checking if the field is housed inside a paragraph/belongs to a paragraph. Maybe we can pass a variable from the parent template to the image template variables?

ru flag
Media entities are reuseable, self-contained, independent entities, you can not pass a variable in there. Instead, try to maniplate the parent, e.g. preprocess the paragraph and remove the alt attribute from the field's render array.
id flag
I thought of doing that. Do you have examples of preprocess paragraph?
4uk4 avatar
cn flag
Put a normal image field in the paragaph type. Then the alt property is stored in the paragraph and you can change it in UI or programmatically for the specific paragraph.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.