Alter a view. Edit view result programmatically | Drupal 8

Alter a view. Edit view result programmatically

Submitted by editor on Fri, 09/30/2016 - 11:16

How to Edit a view result programmatically ?


function MYMODULE_views_pre_render(&$view) {
  if ($view->name == 'view_myviewname') {
    $result = $view->result;
    foreach ($result as $i => $row) {

      $view->result[$i]->field_field_myfieldtext[0]['rendered']['#markup'] = "The new text";


hess (not verified)

Tue, 10/18/2016 - 13:31

How can i edit a view? I mean where should i add this program? I am really new to D8. trying to learn it.

Ruchira (not verified)

Mon, 10/09/2017 - 15:49

If view having empty result then no debug working in views_pre_render(&$view). So waht was another solution to handle no result message programmatically. 

jessicaalex (not verified)

Wed, 07/01/2020 - 23:36

I trully appretiate your work and tips given by you is helpful to me. I will share this information with my family & friends. This is a great website, keep the positive reviews coming. This is a great inspiring .I am pretty much pleased with your good work. You put really very helpful information. I am looking to reading your next post. !!!!

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.