0

I can get the value of the field from the view object like this:

foreach ($view['#view']->result as $row){
      $field_slide_banner = $row->_entity->get('field_slider_banner')->getValue();     
    }

However, in this case I get the target_id of the referenced image file, but I need to get the full rendered output data, which depends on format that I set for this field at the view display, for example, that should be the URL of the image in my case.

In other words, I want to be able to get final output data or HTML markup programmatically for any view field from the given row of executed view object.

3

Try with the following:

foreach ($view->result as $row) {
      //- Change the full with your view mode.
      $render_array = $row->_entity->field_slider_banner->view('full');
      $field_slider_banner_markup = \Drupal::service('renderer')->renderRoot($render_array);
}

another way : works for @JetSet also.

foreach ($view->result as $id => $row) {
  $my_field_value = $view->style_plugin->getFieldValue($id, 'field_name');
}
  • 1
    Thanks, it works and I can see the full output of the field. Also, I have found other solution, where it is possible to get field value without surrounding markup like this: $result = $view->style_plugin->getFieldValue($id, $field); where id is the row number and field is the name of the field. – JetSet Dec 29 '18 at 23:41
  • i'm glad that help, i will add the second way to my answer, in case someone needs it. thanks . – berramou Dec 29 '18 at 23:47

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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