1

How can I programmatically fetch the view path field value?

enter image description here

I am able to fetch title and body, but but I cannot get the path.

function view_path_views_pre_render(\Drupal\views\ViewExecutable $view) {
  kint($view->result);
  if ($view->id() == 'view_idea_shots_for_home_page' && $view->current_display == 'block_3') {
    foreach ($view->result as $value) {
      kint($value->_entity->get('title')->value);
      kint($value->_entity->get('body')->value);
    }
  }
}
  • Did you try $value->_entity->get('path')->value ? – No Sssweat Dec 29 '17 at 13:11
  • Yes iam getting null – Rudra Dec 29 '17 at 15:18
1

path is not a field stored in the entity. It is a computed views field plugin, which can only be outputted by applying Path::render():

$path = $view->field['path']->render($value);

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.