0

Example a view with show fields:

enter image description here

I want retrive array result like this:

[
  [title,
   date_start
   data_end
   ...
  ]
]
1

Use $view->result to get the filtered rows, $view-field for the fields, on which you can use the methods getValue() for the field value and render() for the formatted field as render array.

An example:

use Drupal\views\Views;

  $values = [];
  $view = views::getview('view_example');
  if ($view) {
    $view->execute();
    foreach ($view->result as $rid => $row) {
      foreach ($view->field as $fid => $field ) {
        $values[$rid][$fid . '-value'] = $field->getValue($row);
        $values[$rid][$fid . '-render'] = $field->render($row);
      }
    }
  }
  • ! i try, THZ :D – BOES Nov 3 '16 at 13:23
  • 1
    This worked for me. One thing to note is that tokens and some field formaters don't work with render, $field->advancedRender() works though – lukedekker Nov 29 '18 at 23:57
0

You can use the field "global text" and add all fields inside of this field for show all fields that you have in one field

I hope can help you

  • Unfortunately no, I need the fields in code formatted... it is impossible that you can not do – BOES Nov 2 '16 at 22:14
0

Does this work?

  1. Exclude all the fields from display except the last one.
  2. Be sure to have the Token Module installed and enabled.
  3. Rewrite the output of the last field with the tokens of the needed fields and your array formatting: [[title],...] The available patterns should be visible below.
  4. Adjust the output to your needs and through the rewrite of the last field with the tokens or the formatting of the excluded fields (perhaps necessary for the format of dates and strings).
  • No, i want use result in php. I use View:getView for retrive THE view – BOES Nov 2 '16 at 23:00
  • What are you "getting" in PHP so far. So what happens when you print it? – pehka Nov 3 '16 at 7:45
  • Return entities, not formatted fields. I remember correctly or drupal 7 returned formatted files wit view_get_view ? – BOES Nov 3 '16 at 7:48
  • No, but it's possible to get the view's result. Drupal 8 comes with "views_get_view_result" api.drupal.org/api/drupal/core!modules!views!views.module/… Does that help? This should do the same. – pehka Nov 7 '16 at 20:56
  • Haven't seen the answer above, sorry. – pehka Nov 7 '16 at 20:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.