3 change code to be fit drupal coding standarts
source | link

I ended up getting this to work after finding hook_field_widget_properties_alter. This allows you to, as the hook implies, target the various properties of the widget directly. Global $user seems to provide the $user variable, which allows you to select the role that you want to apply the module to. You can change it from 'administrator' to 'authenticated user', 'anonymous user', or any other needed role to fit your needs.

<?php
function entityreference_widget_field_widget_properties_alter(&$widget, $context) {
  //Assign role that will be affected by the module
  global $user;

  if (in_array('administrator', $user->roles)) {

  function entityreference_widget_field_widget_properties_alter(&$widget, $context) {
    // Change entityreference widget 
    $field = $context['field'];
    if ($context['entity_type'] == 'node' && $field['field_name'] == 'field_review_band') {
      $widget['type'] = 'entityreference_autocomplete';
      $widget['module'] = 'entityreference';
      $widget['settings']['match_operator'] = 'CONTAINS';
      $widget['settings']['size'] = '60';
    }
  }
}

To find out exactly which pieces of the widget needed to be altered, and what to, I created another test field of the type that I wanted to alter my current field to. I then inserted dsm($widget) within the hooks curly brackets of the hook, and then inspected the page with the field on it.

Explanation of dsm() and dpm() for anybody who needs it:

There's so little help anywhere on how to use dsm() or dpm(), and working through this module finally made me understand it. Basically, modules target different elements, and in order to figure out what to target, or what you will be altering, you need to inspect the elements. What dsm() lets you do is view the properties of any given variable (e.g. $form_id most commonly it seems, or in this case $widget or $context) in each of the elements on the page that include it. If anybody stumbles on this and still needs clarification, feel free to ask. It took me forever to figure out how the heck to use dsm().

I ended up getting this to work after finding hook_field_widget_properties_alter. This allows you to, as the hook implies, target the various properties of the widget directly. Global $user seems to provide the $user variable, which allows you to select the role that you want to apply the module to. You can change it from 'administrator' to 'authenticated user', 'anonymous user', or any other needed role to fit your needs.

<?php

//Assign role that will be affected by the module
global $user;

if (in_array('administrator', $user->roles)) {

  function entityreference_widget_field_widget_properties_alter(&$widget, $context) {
    // Change entityreference widget 
    $field = $context['field'];
    if ($context['entity_type'] == 'node' && $field['field_name'] == 'field_review_band') {
      $widget['type'] = 'entityreference_autocomplete';
      $widget['module'] = 'entityreference';
      $widget['settings']['match_operator'] = 'CONTAINS';
      $widget['settings']['size'] = '60';
    }
  }
}

To find out exactly which pieces of the widget needed to be altered, and what to, I created another test field of the type that I wanted to alter my current field to. I then inserted dsm($widget) within the hooks curly brackets of the hook, and then inspected the page with the field on it.

Explanation of dsm() and dpm() for anybody who needs it:

There's so little help anywhere on how to use dsm() or dpm(), and working through this module finally made me understand it. Basically, modules target different elements, and in order to figure out what to target, or what you will be altering, you need to inspect the elements. What dsm() lets you do is view the properties of any given variable (e.g. $form_id most commonly it seems, or in this case $widget or $context) in each of the elements on the page that include it. If anybody stumbles on this and still needs clarification, feel free to ask. It took me forever to figure out how the heck to use dsm().

I ended up getting this to work after finding hook_field_widget_properties_alter. This allows you to, as the hook implies, target the various properties of the widget directly. Global $user seems to provide the $user variable, which allows you to select the role that you want to apply the module to. You can change it from 'administrator' to 'authenticated user', 'anonymous user', or any other needed role to fit your needs.

<?php
function entityreference_widget_field_widget_properties_alter(&$widget, $context) {
  //Assign role that will be affected by the module
  global $user;

  if (in_array('administrator', $user->roles)) { 
    // Change entityreference widget 
    $field = $context['field'];
    if ($context['entity_type'] == 'node' && $field['field_name'] == 'field_review_band') {
      $widget['type'] = 'entityreference_autocomplete';
      $widget['module'] = 'entityreference';
      $widget['settings']['match_operator'] = 'CONTAINS';
      $widget['settings']['size'] = '60';
    }
  }
}

To find out exactly which pieces of the widget needed to be altered, and what to, I created another test field of the type that I wanted to alter my current field to. I then inserted dsm($widget) within the hooks curly brackets of the hook, and then inspected the page with the field on it.

Explanation of dsm() and dpm() for anybody who needs it:

There's so little help anywhere on how to use dsm() or dpm(), and working through this module finally made me understand it. Basically, modules target different elements, and in order to figure out what to target, or what you will be altering, you need to inspect the elements. What dsm() lets you do is view the properties of any given variable (e.g. $form_id most commonly it seems, or in this case $widget or $context) in each of the elements on the page that include it. If anybody stumbles on this and still needs clarification, feel free to ask. It took me forever to figure out how the heck to use dsm().

2 added 2 characters in body
source | link

I ended up getting this to work after finding hook_field_widget_properties_alter. This allows you to, as the hook implies, target the various properties of the hookwidget directly. Global $user seems to provide the $user variable, which allows you to select the role that you want to apply the module to. You can change it from 'administrator' to 'authenticated user', 'anonymous user', or any other needed role to fit your needs.

<?php

//Assign role that will be affected by the module
global $user;

if (in_array('administrator', $user->roles)) {

  function entityreference_widget_field_widget_properties_alter(&$widget, $context) {
    // Change entityreference widget 
    $field = $context['field'];
    if ($context['entity_type'] == 'node' && $field['field_name'] == 'field_review_band') {
      $widget['type'] = 'entityreference_autocomplete';
      $widget['module'] = 'entityreference';
      $widget['settings']['match_operator'] = 'CONTAINS';
      $widget['settings']['size'] = '60';
    }
  }
}

To find out exactly which pieces of the widget needed to be altered, and what to, I created another test field of the type that I wanted to alter my current field to. I then inserted dsm($widget) within the hooks curly brackets of the hook, and then inspected the page with the field on it.

Explanation of dsm() and dpm() for anybody who needs it:

There's so little help anywhere on how to use dsm() or dpm(), and working through this module finally made me understand it. Basically, modules target different elements, and in order to figure out what to target, or what you will be altering, you need to inspect the elements. What dsm() lets you do is view the properties of any given variable (e.g. $form_id most commonly it seems, or in this case $widget or $context) in each of the elements on the page that include it. If anybody stumbles on this and still needs clarification, feel free to ask. It took me forever to figure out how the heck to use dsm().

I ended up getting this to work after finding hook_field_widget_properties_alter. This allows you to, as the hook implies, target the various properties of the hook directly. Global $user seems to provide the $user variable, which allows you to select the role that you want to apply the module to. You can change it from 'administrator' to 'authenticated user', 'anonymous user', or any other needed role to fit your needs.

<?php

//Assign role that will be affected by the module
global $user;

if (in_array('administrator', $user->roles)) {

  function entityreference_widget_field_widget_properties_alter(&$widget, $context) {
    // Change entityreference widget 
    $field = $context['field'];
    if ($context['entity_type'] == 'node' && $field['field_name'] == 'field_review_band') {
      $widget['type'] = 'entityreference_autocomplete';
      $widget['module'] = 'entityreference';
      $widget['settings']['match_operator'] = 'CONTAINS';
      $widget['settings']['size'] = '60';
    }
  }
}

To find out exactly which pieces of the widget needed to be altered, and what to, I created another test field of the type that I wanted to alter my current field to. I then inserted dsm($widget) within the hooks curly brackets of the hook, and then inspected the page with the field on it.

Explanation of dsm() and dpm() for anybody who needs it:

There's so little help anywhere on how to use dsm() or dpm(), and working through this module finally made me understand it. Basically, modules target different elements, and in order to figure out what to target, or what you will be altering, you need to inspect the elements. What dsm() lets you do is view the properties of any given variable (e.g. $form_id most commonly it seems, or in this case $widget or $context) in each of the elements on the page that include it. If anybody stumbles on this and still needs clarification, feel free to ask. It took me forever to figure out how the heck to use dsm().

I ended up getting this to work after finding hook_field_widget_properties_alter. This allows you to, as the hook implies, target the various properties of the widget directly. Global $user seems to provide the $user variable, which allows you to select the role that you want to apply the module to. You can change it from 'administrator' to 'authenticated user', 'anonymous user', or any other needed role to fit your needs.

<?php

//Assign role that will be affected by the module
global $user;

if (in_array('administrator', $user->roles)) {

  function entityreference_widget_field_widget_properties_alter(&$widget, $context) {
    // Change entityreference widget 
    $field = $context['field'];
    if ($context['entity_type'] == 'node' && $field['field_name'] == 'field_review_band') {
      $widget['type'] = 'entityreference_autocomplete';
      $widget['module'] = 'entityreference';
      $widget['settings']['match_operator'] = 'CONTAINS';
      $widget['settings']['size'] = '60';
    }
  }
}

To find out exactly which pieces of the widget needed to be altered, and what to, I created another test field of the type that I wanted to alter my current field to. I then inserted dsm($widget) within the hooks curly brackets of the hook, and then inspected the page with the field on it.

Explanation of dsm() and dpm() for anybody who needs it:

There's so little help anywhere on how to use dsm() or dpm(), and working through this module finally made me understand it. Basically, modules target different elements, and in order to figure out what to target, or what you will be altering, you need to inspect the elements. What dsm() lets you do is view the properties of any given variable (e.g. $form_id most commonly it seems, or in this case $widget or $context) in each of the elements on the page that include it. If anybody stumbles on this and still needs clarification, feel free to ask. It took me forever to figure out how the heck to use dsm().

1
source | link

I ended up getting this to work after finding hook_field_widget_properties_alter. This allows you to, as the hook implies, target the various properties of the hook directly. Global $user seems to provide the $user variable, which allows you to select the role that you want to apply the module to. You can change it from 'administrator' to 'authenticated user', 'anonymous user', or any other needed role to fit your needs.

<?php

//Assign role that will be affected by the module
global $user;

if (in_array('administrator', $user->roles)) {

  function entityreference_widget_field_widget_properties_alter(&$widget, $context) {
    // Change entityreference widget 
    $field = $context['field'];
    if ($context['entity_type'] == 'node' && $field['field_name'] == 'field_review_band') {
      $widget['type'] = 'entityreference_autocomplete';
      $widget['module'] = 'entityreference';
      $widget['settings']['match_operator'] = 'CONTAINS';
      $widget['settings']['size'] = '60';
    }
  }
}

To find out exactly which pieces of the widget needed to be altered, and what to, I created another test field of the type that I wanted to alter my current field to. I then inserted dsm($widget) within the hooks curly brackets of the hook, and then inspected the page with the field on it.

Explanation of dsm() and dpm() for anybody who needs it:

There's so little help anywhere on how to use dsm() or dpm(), and working through this module finally made me understand it. Basically, modules target different elements, and in order to figure out what to target, or what you will be altering, you need to inspect the elements. What dsm() lets you do is view the properties of any given variable (e.g. $form_id most commonly it seems, or in this case $widget or $context) in each of the elements on the page that include it. If anybody stumbles on this and still needs clarification, feel free to ask. It took me forever to figure out how the heck to use dsm().