Restricting view access to a line Item field based on role I have an order page that displays a set of line items.



However, my client wants me to remove the &quot;Responsible Vendor&quot; from display for authenticated users, but it should be displayed for administrators and store manager users.
I have tried the following, but I could not get the desired results.

Hide using Field Permission as described in https://stackoverflow.com/a/9187147/260665

Implementing hook_field_widget_form_alter() following https://stackoverflow.com/q/8009716/260665


I am using the following code.
function bricks_field_widget_form_alter(&amp;$element, &amp;$form_state, $context) {
  if ($context['field']['field_name'] == 'field_responsible_vendor') {
    // Users without the &quot;administer nodes&quot; permission should not see the
    // Responsible Vendor section
    if (!user_access('administer nodes')) {
      unset($element['#options']['field_responsible_vendor']);
    }
  }
}

This hook is never invoked for the field_responsible_vendor field  which represents the Responsible vendor entity reference field.
Now, I tried to dig deep and see why this hook was never invoked for the field in which I am interested. I placed breakpoints in /includes/module.inc with some test code in it.
    // Raj:
    $gotIt = NULL;
    if (is_array($context1)) {
      if ($context1['field'] == 'field_responsible_vendor') {
        $gotIt = $context1['field']['field_name'];
      }
      if (is_array($context1['field'])) {
        if ($context1['field']['field_name'] == 'field_responsible_vendor') {
          $gotIt = $context1['field']['field_name'];
        }
      }
    }

I tried it with $context2 too. The nearest I could get was the following.



I could never get to the field_responsible_vendor field to unset it based on the user roles.
Is there anything I am missing? How can I achieve what I am looking for?
As per @Darvanen's answer, I was able to remove the Responsible vendor value using this code.
function bricks_views_pre_render(&amp;$view) {
  foreach ($view-&gt;result as $lineItem) {
    if (!user_access('administer nodes')) {
      unset($lineItem-&gt;field_field_responsible_vendor);
    }
  }
}

I have the following 2 problems.

This hook is invoked for all views, I would rather like to restrict either the invocation to this page / view alone, or provide a condition to check if it is the page where this code should be executed in order to make sure that performance is not impacted.

The column header is appearing though none of the line items will contain the value for it. I suppose I need to use another hook in order to address this?
The hook method is a good one but you'll need a different hook.

The order page uses a view of line items, not a node display, so you should use a views hook.

I would try either hook_views_pre_render or hook_views_pre_view.

Use dpm($view) (needs devel module) to inspect the view and then modify it however you wish.

To figure out that it was using a view I went to the page, inspected the element in my browser and followed the chain up until I found either a form or a view:





Additional information:


You will definitely need to put an if statement around your code.  Dig through the dpm results for a view id or some other identifier and do something like:

If ([address of view id] != [view id you want]){
  return;
}

To make the column disappear you'll need to unset the field itself, not just the value.  Look in $view somewhere other than -&gt;result.  Sorry, without the dpm output in front of me I can't be more specific than that.