Pro Drupal 7 书中的问题:注释模块
因此,这可能是一个盲目的尝试,但对于任何了解一点 Drupal 或更好的人来说,已经实现了第 1 章中的注释模块。 Pro Drupal 7 开发之 2
您知道如何更改注释模块以便所有用户都可以注释吗?目前,只有管理员可以注释,并且它作为编辑的扩展呈现。
使用的具体代码位于此存储库中(几乎直接来自本书): http://github.com/dsharkey/Drupal-Module-Development--Annotate-Module
此外,我根本没有看到注释模块是如何被呈现的?我相信它是通过以下几行 PHP 实现的(来自 annotate.admin.inc):
$instance = array(
'field_name' => 'annotation',
'entity_type' => 'node',
'bundle' => $key,
'label' => t('Annotation'),
'widget_type' => 'text_textarea_with_summary',
'settings' => array('display_summary' => TRUE),
'display' => array(
'default' => array(
'type' => 'text_default',
),
'teaser' => array(
'type' => 'text_summary_or_trimmed',
),
),
);
$instance = field_create_instance($instance);
但我不确定除了创建实例并将其自身附加到节点之外,它还能做什么。为什么它会显示在原来的位置(作为编辑旁边的选项)?
谢谢大家!
So this is likely a shot in the dark, but for anyone out there who knows a bit of Drupal and better yet has implemented the annotate module from Ch. 2 of Pro Drupal 7 Development
Do you know how to alter the annotate module so all users can annotate? Right now, only the admin can annotate and it's being presented as an extension to editing.
The specific code being used is in this repository (pretty much straight from the book): http://github.com/dsharkey/Drupal-Module-Development--Annotate-Module
Further, I'm not really seeing how the annotate module is told to be presented at all? I believe its by the following lines of PHP (from annotate.admin.inc):
$instance = array(
'field_name' => 'annotation',
'entity_type' => 'node',
'bundle' => $key,
'label' => t('Annotation'),
'widget_type' => 'text_textarea_with_summary',
'settings' => array('display_summary' => TRUE),
'display' => array(
'default' => array(
'type' => 'text_default',
),
'teaser' => array(
'type' => 'text_summary_or_trimmed',
),
),
);
$instance = field_create_instance($instance);
But I'm not sure how that does anything more than create an instance and attach itself to a node. Why does it display where it does (as an option next to edit)?
Thanks all!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您说“作为编辑旁边的选项”时,我不确定您指的是什么,但是您上传的代码(并仔细检查书籍本身、使用的代码)不会导致这种情况。事实上,当您编辑启用注释的节点时,您应该只看到正文字段下方的字段:
原因它仅在您编辑现有节点时显示(而不是在您创建新节点时显示)与您的第一个问题相关,即不允许所有用户注释该节点:在
hook_node_load()
实现中,它专门检查编辑节点的用户是否与节点的所有者相同;如果不是,它会隐藏注释字段:因此唯一应该看到注释字段的人是所有者。如果您希望允许具有编辑访问权限的任何人对节点进行注释,请删除该功能。
至于允许任何人对节点进行注释作为编辑节点本身的单独功能,这不是示例的内容,并且与所使用的代码完全分开。您必须在其他地方寻找解决方案,并查看 Drupal.org 项目 Annotate 等示例以了解方法去做它。基本上,注释将是它们自己的独立实体,它们将引用节点,这与注释的工作方式非常相似。
但如果我这么大胆的话,您可能会遇到 Pro Drupal 7 Development 的一个大问题,因为它不像以前的版本那样提供良好的开发参考:它没有解释事情非常好,在小事情上花费了太多时间,而在真正重要的事情上花费了太多时间,引入了非常糟糕的实践(包括注释示例中的几个),并且完全错过了 Drupal 7 引入的大部分内容。我建议您查看Drupal 7 模块开发。
I'm not sure what you're referring to when you say "as an option next to edit", but the code you uploaded (and double-checking the book itself, the code used) wouldn't cause that. In fact, you should just see a field below the body field when you edit a node with annotations enabled:
The reason it only shows up when you edit an existing node (and not when you create a new node) is related to your first question about it not letting all users annotate the node: in the
hook_node_load()
implementation, it specifically checks to see if the user editing the node is the same as the owner of the node; if it isn't, it hides the annotation field:So the only person who should ever see the annotate field is the owner. If you want to allow anyone with edit access annotate the node, remove that function.
As for allowing anyone to make annotations to the node as a separate function to editing the node itself, that's not what the example was about and is entirely separate from the code used. You'll have to seek elsewhere for that and look at examples like the Drupal.org project Annotate for ways to do it. Basically, the annotations would be their own separate entities that would reference the node, much in the same way comments work.
But if I may be so bold, you've run into a big problem with Pro Drupal 7 Development in that it's not as good a reference for development as the previous editions were: it doesn't explain things very well, spends too much time on minor things and not enough time on really major things, introduces really bad practices (including several in the annotate example), and completely misses large sections of what Drupal 7 introduced. I'd recommend checking out Drupal 7 Module Development instead.