I'm using hook_field_widget_properties_alter to successfully set the widget type of some fields to 'options_select', but when trying to set others to entityreference_autocomplete, I get the error, "Class name must be a valid object or a string in mysite\includes\common.inc". Here's the code:

/*implementation of hook form alter*/
function mymodule_overrides_field_widget_properties_alter(&$widget, $context){ 
  // set widget type to options_select for field_expertisetags and og_group_ref
     $widget['module'] = 'entityreference';
     $widget['type'] = 'entityreference_autocomplete_tags';

Any thoughts as to the cause?

1 Answer 1


I discovered that the target field was of a type that required different settings. I solved it by entering this:

$widget['active'] = '1';
$widget['#access'] = '1';
$widget['module'] = 'taxonomy';
$widget['type'] = 'taxonomy_autocomplete';
$widget['settings']['autocomplete_path'] = 'taxonomy/autocomplete';
$widget['settings']['size'] = '60';

I also realized you can go to the content type, select a field type and the underlying html for that dropdown will reveal the field type module value, and the settings under the widget dropdown will reveal the 'type' value you need to use. Hope that helps someone.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.