注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

John's Blog

天空,有梦就可以飞翔!

 
 
 

日志

 
 
关于我

刚走出校园的毕业生,就读计算机网络专业,对网站建设有一定的基础。开始探求Drupal已有一段时间,对Drupal的发展很是看好。现就职于深圳慧衡科技有限公司(intematrix.cn),它是一家专门服务于中国及海外中小企业的网络营销分析和优化服务提供商。 QQ交流群:44581272

网易考拉推荐

Drupal-Open Atrium:Build a feature  

2010-01-30 21:03:49|  分类: drupal学习 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

Build a feature

Setting up a reasonable development environment

  1. Install drush
  2. Turn on administration menu items at DE<admin/atriumDE< (check the "Show all administration pages" checkbox)
  3. Enable DE<develDE< module

Checklist

  1. Build feature (CCK, Views, Context, etc. and exported using Features module), can be done on non-atrium site
  2. Add feature and dependency modules to codebase in DE<admin/modules/contribDE< and DE<admin/modules/featuresDE<
  3. Enable your feature
  4. Add spaces metadata to feature DE<.infoDE< file
  5. Add spaces filters, access control to feature views and to any custom menu callbacks
  6. Export any necessary variables (node type settings, etc.) using DE<strongarmDE<
  7. Export any necessary user permissions
  8. Add any dashboard blocks to DE<hook_atrium_dashboard()DE<
  9. Add icon, CSS with DE<drupal_add_css()DE< in DE<hook_init()DE<

Step-by-step

1. Build feature

Features can be built using common Drupal.org site building modules (Views, CCK, Context, etc.) but you can also leverage other specialized modules like FeedAPI, Faceted Search, etc. For an overview of how to build a feature you can watch the screencast Making and Using Features in Drupal. For the rest of this HOWTO I will be using the Imageboard feature built in this screencast as the example feature.

2. Add feature and dependency modules to codebase

Next we'll put our feature module and its dependencies in the Atrium codebase. We'll untar the imageboard feature to

DE<sites/all/modules/features/imageboardDE<

And its dependencies DE<imagefieldDE< and DE<filefieldDE< to

DE<sites/all/modules/contrib/imagefield
sites/all/modules/contrib/filefieldDE<

3. Enable your feature

Next, we'll enable the dependent modules DE<imagefieldDE< and DE<filefieldDE< and then the Imageboard feature on DE<admin/build/featuresDE<.

4. Add spaces metadata to feature DE<.infoDE< file

Next we will add some metadata to the feature's info file to let Spaces know that the feature can be used with Spaces.

DE<core = "6.x"
package = "Features"
project = "imageboard"
name = "Imageboard"
description = "Imageboard with commenting."
...
spaces[types][] = "og"
spaces[types][] = "user"DE<

If you'd like your feature to offer a menu item that spaces can toggle on and off add a line for it

DE<features[menu][] = "imageboard"DE<

You can specify each type of space that the feature is compatible with or say that the feature is compatible with all space types by using the following line:

DE<spaces[types] = "all"DE<

Finally, clear your cache with a

DE<$ drush cache clearDE<

and turn on the feature in one of your groups.

5. Add spaces filters, access control to feature views and to any custom menu callbacks

The imageboard feature is pretty usable at this point but you'll notice a few problems. If you enable the feature in two groups, you'll see that any groups can see the images posted in the other groups. We need to add a view filter to limit the imageboard view to nodes only in that space. In addition, we need to add an access plugin so that even when the feature is off users cannot access the imageboard by typing DE<mygroup/imageboardDE< into the url.

  1. Go to DE<admin/build/viewsDE< and edit the feature view
  2. Add the Node in current space filter (or User in current space if you are building a view of users)
  3. You probably want to set the "When not in a space" dropdown to "Hide all results." "Show all results" is useful for blocks that may be seen in a space and outside (e.g. in the site dashboard).
  4. Click on Access under the view's Basic settings and choose the Spaces feature plugin. Choose your feature in the next dropdown. This will ensure that this view is only accessible when enabled for a given space.

Do these steps for each of the views in your feature. Also note that if you have built any views that don't use DE<nodeDE< as their base table (e.g. DE<commentsDE<), you will need to add a relationship back to the node table to enable access restrictions (use the node access filter) and to filter content for the current space.

6. Export any necessary variables (node type settings, etc.) using DE<strongarmDE<

Strongarm is a module that lets you enforce variable settings that are necessary for your feature to work properly. Some of the most common variables you'll want to export are your node type settings. You can look at all the variables that might relate to your node type using the following drush command:

DE<$ drush strongarm | grep _image

atrium_update_type_image
comment_anonymous_image
comment_controls_image
comment_default_mode_image
...
content_profile_use_image
feedapi_image
feedapi_settings_image
form_build_id_image
node_options_image
notifications_content_type_image
og_content_type_usage_image
show_diff_inline_image
show_preview_changes_image
upload_imageDE<

To find out the value of a variable (or multiple variables in this case), you can use

DE<$ drush strongarm atrium_update_type_image node_options_image

array (
  'atrium_update_type_image' => 1,
  'node_options_image' =>
  array (
    0 => 'status',
  ),
)DE<

You can then export the variables by copying and pasting your strongarmed variables into DE<hook_strongarm()DE<. You can implement this hook and other custom hooks in DE<imageboard.moduleDE< which will be left alone by the features module when running DE<drush features updateDE< (or updating in the UI).

DE</**
* Implementation of hook_strongarm().
*/
function imageboard_strongarm() {
  $conf = array (
    'atrium_update_type_image' => 1,
    'comment_anonymous_image' => 0,
    'comment_controls_image' => '3',
    ...
    'feedapi_settings_image' => array('enabled' => 0),
    'node_options_image' => array('status'),
    'show_diff_inline_image' => 0,
    'upload_image' => 0,
    'notifications_content_type_image' => array(),
  );
  return $conf;
}DE<

7. Export any necessary user permissions

Your feature will likely want to set up sensible permissions out of the box. Atrium comes with 4 different user roles and features should try to stay away from adding additional roles if possible:

  • DE<anonymous userDE< (no access)
  • DE<authenticated userDE< (can join groups and use features normally)
  • DE<managerDE< (has access to make, configure and manage groups)
  • DE<adminDE< (has access to sitewide configuration, maintenance)

Once you've configured the permissions your feature needs for these different roles, you can export your permissions by adding them to DE<imageboard.infoDE<:

DE<features[user][] = "create image content"
features[user][] = "edit own image content"
features[user][] = "delete own image content"DE<

Then run

DE<$ drush features update imageboardDE<

And you'll see that the DE<hook_user_default_permissions()DE< has been added to DE<imageboard.features.incDE<.

8. Add any dashboard blocks to DE<hook_atrium_dashboard()DE<

Your feature can provide additional dashboard blocks by implementing DE<hook_atrium_dashboardDE< in DE<imageboard.moduleDE<:

DE</**
* Implementation of hook_atrium_dashboard().
*/
function imageboard_atrium_dashboard() {
  $blocks = array();
  $blocks['views_imageboard_comments-block_1'] = array(
    'module' => 'views',
    'delta' => 'imageboard_comments-block_1',
    'weight' => 20,
    'region' => 'right',
  );
  return $blocks;
}DE<

The format is similar to that of exported contexts. You can limit the block to only show up on user space dashboards (or any other space type) by adding

DE<'spaces' => array('user', 'og'),DE<

To each block's entry.

9. Add icon, CSS with DE<drupal_add_css()DE< in DE<hook_init()DE<

Your feature can provide its own menu icon and any custom CSS by adding a stylesheet in DE<hook_init()DE<:

DE</**
* Implementation of hook_init().
*/
function imageboard_init() {
  drupal_add_css(drupal_get_path('module', 'imageboard') .'/imageboard.css');
}DE<

Icons should be 40x40 PNG-24 files.

The CSS for your icon will look like this:

DE<#features-menu li a.icon-imageboard span.icon { background:url(images/icon.png) no-repeat; }DE<

Note that the class DE<.icon-imageboardDE< is generated based on the path of your menu items. If you have multiple menu items, you can specify a separate icon for each based on the path class.

  评论这张
 
阅读(713)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2016