How can I theme the markup for the labels in a set of radio options on a specific form item? Given this form item defined in a custom module;

$form['my_items'] = [
  '#type' =&gt; 'radios',
  '#title' =&gt; $this-&gt;t('Items'),
  '#options' =&gt; $optionsSet // array of options pulled from a data source
];


How can I modify the label of each option to include a small image to the right of the text? In my case, the image is stored in the same dataset alongside each label.

I'm going to guess this has something to do with adding a '#theme' attribute, but I haven't been able to determine the entire process for setting that up.
You'll need to massage the $optionsSet array so it's structured like this:

$optionsSet = [
  'option1' =&gt; '&lt;img scr="../images/option1.jpg"/&gt;option 1',
  'option2' =&gt; '&lt;img scr="../images/option2.jpg"/&gt;option 2',
];

$form['my_items'] = [
  '#type' =&gt; 'radios',
  '#title' =&gt; $this-&gt;t('Items'),
  '#options' =&gt; $optionsSet,
];