You are here

function search_autocomplete_views_pre_render in Search Autocomplete 7.3

Implements hook_views_pre_render().

File

./search_autocomplete.view_autocomplete.inc, line 28
Search Autocomplete Enables autocomplete functionality on search fields.

Code

function search_autocomplete_views_pre_render(&$view) {
  if (isset($view->plugin_name) && $view->plugin_name == 'search_autocomplete') {

    // Support for Video field.
    if (!empty($view->result)) {

      // Process each View result.
      foreach ($view->result as $row => $result) {

        // Only process the entity fields defined by the View.
        foreach ($view->field as $field_name => $field) {
          if ($field instanceof views_handler_field_field) {
            if ($field->field_info['type'] == 'video') {

              // Get the Video URL.
              $video = $field
                ->get_value($view->result[$row]);
              $url = file_create_url($video[0]['uri']);
              $render_array = array(
                '#type' => 'markup',
                '#markup' => filter_xss($url),
              );

              // Substitute embed code with URL. @todo Add support for escaped embed codes.
              $view->result[$row]->{'field_' . $field_name}[0]['rendered'] = $render_array;
            }
          }
        }
      }
    }
  }
}