You are here

function asset_widget_pre_render_textfield in Asset 7

Text field element pre_render function.

1 string reference to 'asset_widget_pre_render_textfield'
asset_widget_element_info_alter in modules/asset_widget/asset_widget.module
Implements hook_element_info_alter().

File

modules/asset_widget/asset_widget.module, line 248
Code for the Asset widget module.

Code

function asset_widget_pre_render_textfield($element) {
  if (!isset($element['#entity_type'])) {
    return $element;
  }
  static $attached = array();

  // Skip static caching for multiple enityreference fields.
  // In other cases highlight will be disabled after elements rebuild.
  // @todo: here it's possible to add caching. Same for asset_widget_pre_render_text_format().
  if (empty($attached[$element['#id']]) || current_path() == 'system/ajax') {
    if ($field = field_info_field($element['#field_name'])) {
      if ($field['active'] && $field['type'] == 'entityreference') {
        if (!empty($field['settings']['target_type']) && $field['settings']['target_type'] == 'asset') {
          $asset_types = !empty($field['settings']['handler_settings']['target_bundles']) ? array_keys($field['settings']['handler_settings']['target_bundles']) : array();
          _asset_widget_element_attach_asset_widget($element, $asset_types);
        }
      }
    }
    $attached[$element['#id']] = $element['#id'];
  }
  return $element;
}