Skip to main content
fixed typo in hook
Source Link
Dave Bruns
  • 1.6k
  • 17
  • 27

Based on @clive's comment above, I adjusted the code to check that $entity is actually present. I'm not sure if this is a problem unique to my install or not. I only saw the error when viewing a node of type 'lesson' through a paged view that depends on some custom relationship code, so entirely possible the error is mine somewhere in a custom module.

function HOOK_utility_field_accessHOOK_field_access($op, $field, $entity_type, $entity, $account) {

      //Check to make sure we have an entity. Abort if not.
      if (is_object($entity)) {
    
        //Check video field only when attached to 'lesson'.
        if ($field['field_name'] == 'field_video' && $entity_type == 'node' && $op == 'view' && $entity->type == 'lesson') {
    
          //Grant access only if user is logged in.
          if ($account->uid > 0) {
            return TRUE;
          }
          return FALSE;
        }
      }
    }

Based on @clive's comment above, I adjusted the code to check that $entity is actually present. I'm not sure if this is a problem unique to my install or not. I only saw the error when viewing a node of type 'lesson' through a paged view that depends on some custom relationship code, so entirely possible the error is mine somewhere in a custom module.

function HOOK_utility_field_access($op, $field, $entity_type, $entity, $account) {

      //Check to make sure we have an entity. Abort if not.
      if (is_object($entity)) {
    
        //Check video field only when attached to 'lesson'.
        if ($field['field_name'] == 'field_video' && $entity_type == 'node' && $op == 'view' && $entity->type == 'lesson') {
    
          //Grant access only if user is logged in.
          if ($account->uid > 0) {
            return TRUE;
          }
          return FALSE;
        }
      }
    }

Based on @clive's comment above, I adjusted the code to check that $entity is actually present. I'm not sure if this is a problem unique to my install or not. I only saw the error when viewing a node of type 'lesson' through a paged view that depends on some custom relationship code, so entirely possible the error is mine somewhere in a custom module.

function HOOK_field_access($op, $field, $entity_type, $entity, $account) {

      //Check to make sure we have an entity. Abort if not.
      if (is_object($entity)) {
    
        //Check video field only when attached to 'lesson'.
        if ($field['field_name'] == 'field_video' && $entity_type == 'node' && $op == 'view' && $entity->type == 'lesson') {
    
          //Grant access only if user is logged in.
          if ($account->uid > 0) {
            return TRUE;
          }
          return FALSE;
        }
      }
    }
Source Link
Dave Bruns
  • 1.6k
  • 17
  • 27

Based on @clive's comment above, I adjusted the code to check that $entity is actually present. I'm not sure if this is a problem unique to my install or not. I only saw the error when viewing a node of type 'lesson' through a paged view that depends on some custom relationship code, so entirely possible the error is mine somewhere in a custom module.

function HOOK_utility_field_access($op, $field, $entity_type, $entity, $account) {

      //Check to make sure we have an entity. Abort if not.
      if (is_object($entity)) {
    
        //Check video field only when attached to 'lesson'.
        if ($field['field_name'] == 'field_video' && $entity_type == 'node' && $op == 'view' && $entity->type == 'lesson') {
    
          //Grant access only if user is logged in.
          if ($account->uid > 0) {
            return TRUE;
          }
          return FALSE;
        }
      }
    }