hook_field_widget_form_alter - modify specified field only I'd like to use a hook to modify a widget, but only for a named field.

Use case: a form has an entity reference to another content type, using an options_buttons widget (a list of available courses the user can apply for). Rather than just the title alongside each checkbox, I'd like to display some extra fields from the content type such as date, a URL etc.

The documentation suggests $context['widget'] ("The widget plugin instance.") is the place to look, however a var_dump of that just seems to give me lots of protected properties and no clear way of getting the field name.

Essentially I'm after a D8 version similar to this old example I found:

if ($context['field']['field_name'] != 'field_bannerimage') return;
So it's actually to be found in $context['items']

if (($context['items']-&gt;getName() != 'field_myfield')) {
  return;
}

// if still here, our field matches. do something


Also note you can be more efficient by using the WIDGET_TYPE hook, e.g. for my "Check boxes/radio buttons" widget:

function hook_field_widget_options_buttons_form_alter(...)