views_pre_render add class item to a row

by purencool   Last Updated September 11, 2019 05:07 AM - source

When pre-rendering a view row is there a way to inject a class into a single item, allowing me to add a new background colour to the event item highlighting its importance? Below the is the what I have so far.

  if ((int)\Drupal::currentUser()->id() === 1) {
    foreach ($view->result as $key => $value) {
      try {
        $field_result_value = $value->_entity->field_display->getValue();
        if (isset($field_result_value[0]) && (int)$field_result_value[0]['value'] === 1) {
          // add a class to the change the background color to hi-light its importance 
        }
      } catch (Exception $e) {
        \Drupal::logger('viewoveride_pnc_cal_views_overrides')->error($e->getMessage());
      }
    }
  }
Tags : views


Related Questions


Alter the moderation state in the Content view Drupal 8

Updated February 28, 2018 21:07 PM


Group items in Views by value in Field Collection

Updated July 20, 2015 13:03 PM

List of referenced entities appended to a node

Updated January 12, 2017 08:03 AM