chx noticed this this morning and asked me to file an issue:
$info = array(
'#theme' => 'field',
'#weight' => $this->weight,
'#title' => $instance['label'],
'#access' => field_access($field, 'view', $entity_type, $entity),
'#label_display' => $this->label,
'#view_mode' => $this->viewMode,
'#language' => $langcode,
'#field_name' => $field['field_name'],
'#field_type' => $field['type'],
'#field_translatable' => $field['translatable'],
'#entity_type' => $entity_type,
'#bundle' => $entity->bundle(),
'#object' => $entity,
'#items' => $items,
'#formatter' => $this->getPluginId(),
);
field_access() is being called with the wrong order of arguments, so clearly we need more test coverage for field access restrictions.
Also, it concerns me a little that field_access($garbage, $garbage) is TRUE. ;)
Comments
Comment #1
swentel commentedSo weird, and there are tests re: access, but apparently they don't test well enough. I'll have a look at it later.
Comment #2
swentel commentedLet's see if things fail now, that would be ironic :)
Comment #3
swentel commentedOk, with tests now.
Comment #4
swentel commentedaargh, ignore those.
Comment #5
swentel commentedThis should be better.
Comment #7
swentel commentedOk, that was a bit too optimistic to use an extra permission, turns out other modules use the field_test as well. Different permission, a completely different field and a specific check in field_test_field_access().
Comment #8
xjmThanks @swentel, that looks great. A couple minor notes about the test:
Missing docblocks here.
Minor, but
bypass node accessshouldn't be needed if there's no node access module enabled? It might be better to not mix node and field access in the test, so better to use thecreate type contentpermission (or, maybe better, just create the node withdrupalCreateNode()).Should be LANGUAGE_NOT_SPECIFIED rather than
undI think.I'd expand these comments a little here (or somewhere in the method) to explain that
field_test.moduleimplements access control for this field name.Minor, but we should probably use $node->nid here rather than hardcoding 1.
I'd add an inline comment here indicating what test this permission is used in, and how. Edit: Or really just what it does, "Only grant view access to test_view_field fields when the user has 'view test_view_field content' permission."
Comment #9
swentel commentedNew patch
- use drupalCreateNode() so we don't need the bypass node access permission
- more comments
Comment #10
swentel commentedSeriously, 'This is the some text', sigh, changed to 'This is some text'.
Comment #11
Stalski commentedLook good and ready to go
Comment #12
xjm+1, looks great.
Comment #13
xjmOh, the class still needs a docblock.
Oops, "specifically" mispelled here. :)
Comment #14
swentel commentedHere goes.
Comment #15
xjmYep!
Comment #16
webchickNice catch, and nice tests! Reminded me a little of #139921: Add "View any %nodetype% content" and "View own %nodetype% content" permissions. Oh wouldn't it be lovely if someone could implement that lovely feature before feature freeze..? ;) ;)
Committed and pushed to 8.x. Thanks!
Comment #17.0
(not verified) commented.