Spaces provides a framework for creating new features and exposing them to your site's spaces for use and customization. This is a guide to key steps in creating your own spaces feature.
Overview
Before you get started, you will want to be familiar with the following drupal modules:
To take full advantage of spaces feature, you will also want to have a good knowledge of PHP and the Drupal Forms API.
The concept and components to a feature are simple. A feature tends to consist of:
- one or more content types
- pages that display this content (often provided by Views)
- blocks that provide additional tools or displays related to this content
- an interface for navigating, creating and managing the content
Views
If you are using Views to generate your primary page callbacks, you will want to take some additional steps to make sure they will work with spaces.
Access restrictions
You can enable space-based access restrictions on a view under Basic settings > Access > Spaces feature. You can then choose the feature for which access to the view should be tied. For example, if group A enables your feature as public, the view will permit access to all users, while when group B might make the feature private, in which case the view will permit access to only members.
Filters
On all views you build you should probably include the views spaces filter. It is in Filters > Spaces > Node in current space. It will give you the following options when you enable it:
- Apply at all times / Apply only in a space
- Applies to any space / Applies only in a group space / Applies only in a [other space types] etc.
This gives you considerable flexibility when building your feature view. Here are some examples of how to use these options:
-
A taxonomy view that shows only nodes in the current space, but all nodes the user has access to outside of spaces: Apply only in a space + applies to any space
-
A shoutbox view that shows shouts only in a group space and is empty in all other cases: Apply at all times + applies only in a group space.
These parameters are passed to the views filter defined by a space type so that the space class can decide how to best act on them.
Context
The context definition of a feature is the central source of information about a feature. Any context definitions with the namespace spaces and attribute feature will be made available as a spaces feature. In addition, these definitions should make use of the spaces feature context getter.
When building your context definition, you will want to associate any pages that should be part of your feature (views, node types, book pages, etc.) and any menus and blocks that should respond when a user is viewing your feature. The spaces feature settings allow you to define a label, description, and menu item for your feature. In addition, you can choose which space types can use your feature.
Implementing settings
You may need to add additional settings to help your feature along. Currently, there is a space_setting class & additional hook_spaces_settings() hook for registering settings. You can also attach a setting to a specific feature by including it in an exported context definition:
<?php
/**
* Implementation of hook_context_ui_define().
*/
function mymodule_context_ui_define() {
$items = array();
$items[] = array(
'namespace' => 'spaces',
'attribute' => 'feature',
'value' => 'my_feature',
...
'spaces' => array(
'label' => 'My awesome feature',
'description' => 'This is an example feature',
'types' => array('site', 'og'),
'menu' => array(array('title' => 'My feature', 'href' => 'my-feature')),
'settings' => array('my_feature' => new mymodule_spaces_setting()),
),
);
}
?>The settings get stored in the spaces tables and are retrieved when the space is loaded. You can access them by retrieving the space object like this:
<?php
$space = spaces_get_space();
print_r($space->settings['my_feature']);
?>