You are here

function _asset_widget_element_attach_asset_widget in Asset 7

Attach asset widget form to element.

2 calls to _asset_widget_element_attach_asset_widget()
asset_widget_pre_render_textfield in modules/asset_widget/asset_widget.module
Text field element pre_render function.
asset_widget_pre_render_text_format in modules/asset_widget/asset_widget.module
Text format element pre_render function.

File

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

Code

function _asset_widget_element_attach_asset_widget(&$element, $asset_types = array(), $additional_classes = array()) {
  if (empty($additional_classes) && !empty($asset_types) && is_array($asset_types)) {
    $additional_classes = array(
      'match-field',
    );
    foreach ($asset_types as $asset_type) {
      if (empty($additional_classes[$asset_type])) {
        $additional_classes[$asset_type] = "match-{$asset_type}";
      }
    }
  }
  if (!empty($additional_classes) && is_array($additional_classes)) {
    if (isset($element['value'])) {
      if (!isset($element['value']['#attributes']['class'])) {
        $element['value']['#attributes']['class'] = array();
      }
      $element['value']['#attributes']['class'] = array_merge($element['value']['#attributes']['class'], $additional_classes);
    }
    elseif (isset($element['#attributes'])) {
      if (!isset($element['#attributes']['class'])) {
        $element['#attributes']['class'] = array();
      }
      $element['#attributes']['class'] = array_merge($element['#attributes']['class'], $additional_classes);
    }
  }

  // Add widget HTML to page.
  asset_widget_add_to_page(TRUE);
}