Thursday, March 19, 2020

How to override the view field in drupal 7 using hook

/**
 * Implements hook_views_pre_render().
 */
function Moduelname_views_pre_render(&$view) {
  global $user;

  if ($view->name == 'conversation_enquiry' && $view->current_display = 'panel_pane_1') {
    $entity_form = $view->result;
    foreach ($view->result as $result) {
      $request_sent_status = $result->field_conversation_status[0]['rendered']['#markup'];
      if ($request_sent_status == "Approved") {
        $result->field_conversation_status[0]['rendered']['#markup'] = 'Offer made';
      }
    }
    if (in_array('administrator', $user->roles) || $entity_form[0]->bat_types_field_data_field_listing_enquiry_type_ref_uid == $user->uid) {
      $view->field['field_st_int_iden']->options['exclude'] = FALSE;
      $view->field['field_listing_enquiry_type_ref']->options['exclude'] = TRUE;
    }
    else {
      $view->field['field_st_int_iden']->options['exclude'] = TRUE;
    }

    $view_form_first_name = $view->display_handler->view->result[0]->field_field_listing_enquiry_name[0]["rendered"]["#markup"];
    $view_form_last_name = $view_form_first_name . ' ' . $view->result[0]->field_field_listing_enquiry_last_name[0]["rendered"]["#markup"];
    $view->display_handler->view->result[0]->field_field_listing_enquiry_name[0]["rendered"]["#markup"] = $view_form_last_name . ' ' . $output;
  }
}

No comments:

Post a Comment

If you have any problem please let me know.