使用 CCK 在 Drupal 中按节点创建日期访问字段
我正在寻找一种特定的行为,该行为授予基于节点创建日期时间查看一个或多个 cck 字段的权限。
我特别需要:
授予角色 A:对所有 CCK(旧的和新的)的完全访问权限 授予角色 B:访问所有 CCK,但仅限于节点中存在时间早于 1 年的 CCK 匿名用户:无法访问 CCK 字段
我怎样才能得到这个结果?
I'm looking for a particular behaviour that grant permission to see one or more cck field based on date time creation of node.
In particular i need to:
Grant to role A: Full access to all CCK (old and new)
Grant to role B: Access to all CCK but ONLY to ones present in node OLDER than 1 Year
Anonymous user: No access to CCK field
How can i get this result?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您想要控制字段级别的权限,因此我会避免使用
hook_nodeapi()
相反,我建议您使用hook_field_access
(或使用hook_nodeapi
的组合) code> 和hook_field_access()
伪代码示例:
查看正在调用的钩子
http://api.lullabot.com/content_access
hook_field_access()
是Drupal 6 中可通过 CCK 模块获取。在 Drupal 7 中它是核心。You want to control permissions on a field level so I would avoid using
hook_nodeapi()
Instead I would suggest you usehook_field_access
(or use a combination ofhook_nodeapi
andhook_field_access()
example in pseudocode:
See to see the hook being called
http://api.lullabot.com/content_access
hook_field_access()
is available in Drupal 6 from the CCK module. In Drupal 7 it is in core.我会在自定义中实现
hook_nodeapi()
模块,并在$op == 'view'
上检查正确的节点类型和用户角色。根据角色,我将从“$node->content”数组中删除有问题的字段条目。请注意,需要在 CCK 之后调用自定义模块才能使其正常工作,否则 CCK 字段在“$node->content”数组中尚不可用。因此,根据其名称,可能需要将自定义模块权重更改为高于 CCK 的值。
如果同样的逻辑也需要应用于节点编辑表单,则可以对
$op == 'prepare'
执行相同的操作。I would implement
hook_nodeapi()
in a custom module, and on$op == 'view'
check for the proper node type and the user role. Depending on the role, I'd remove the field entry in question from the `$node->content' array.Note that the custom module needs to be invoked after CCK for this to work, as otherwise the CCK fields are not yet available in the `$node->content' array. So depending on its name, one might need to alter the custom modules weight to a value higher than that of CCK.
If the same logic needs to be applied for node edit forms as well, one would do the same on
$op == 'prepare'
.感谢大家的建议!
hook_field_access() 是我正在寻找的解决方案。
我以前使用过 $node->field_FIELDNAME[0]['#value'] 但我不'不喜欢放入我的主题(或 template.php 中)功能以供用户访问。还有主题的问题,这个解决方案没有给我使用 Semantic CCK 模块简单干净的 HTML 输出的可能性!
再次感谢!
再见!
诗。为什么我的帖子不在最后一篇之后???
Thanks to all for suggestions!
The hook_field_access() is the solution i'm looking for.
I previously used the $node->field_FIELDNAME[0]['#value'] but I don't like to put in my theme (or in template.php) functions for user access. There was also the problem of theming, this solution didn't give my possibility for an easy and clean HTML output using Semantic CCK module!
Thanks again!
Bye!
Ps. why my post is not after the last??!!
这很简单,创建 node-{YOURTYPE}.tpl.php,为其设置主题,然后添加条件以显示日期的字段依赖性...
It's easy, create node-{YOURTYPE}.tpl.php, theme it, and add conditions to show fields dependency from dates...