Grayside.Org

Home

Optional Spaces Integration for a View

grayside — Tue, 06/15/2010 - 13:05

If you want to make an exported [node-based] View smoothly integrate with Spaces, you can use the following code to modify the View structure with the “Content in current space” filter. This filter does nothing if the View is not itself in a Space, otherwise it restricts all results to content in the same space. Add any conditions you want to control whether the Spaces integration is applied.

<?php
/**
* Implementation of hook_views_default_views_alter().
*/
function custom_views_default_views_alter(&$views) {
  if (
module_exists('spaces')) {
   
$views['view_name_here']->display['default']->display_options['filters']['current'] = array(
     
'operator' => 'all',
     
'value' => '',
     
'group' => '0',
     
'exposed' => FALSE,
     
'expose' => array(
       
'operator' => FALSE,
       
'label' => '',
      ),
     
'id' => 'current',
     
'table' => 'spaces',
     
'field' => 'current',
     
'relationship' => 'none',
    );
  }
}
?>

If you would like to take it a step further, and create OpenAtrium features integration, insert the following:

<?php
$views
['view_name_here']->display['default']->display_options['access'] = array(
 
'type' => 'atrium_feature',
 
'spaces_feature' => 'feature_name',
 
'perm' => 'access content', // or any other permission
);
?>

hook_views_default_views_alter() fires off before the View is cached, so be sure to clear your cache after adding this code to see the results.

This code snippet is a finding from my work on OpenAtrium-FeatureServer integration.

  • drupal
  • spaces
  • views
  • Add new comment

Or, of course, you could just

Mysterious Stranger (not verified) — Tue, 06/15/2010 - 18:22

Or, of course, you could just use the built-in “Node is in this space” filter…..

  • reply

That's What This Does

grayside — Wed, 06/16/2010 - 08:10

Hello Stranger,

The code snippet above does exactly that. However, it allows you to do it without modifying the view directly.

This allows you to add the View into Spaces with additional logic of your choice, to avoid broken filter handlers if someone is using the View but not the Spaces module, and lastly to integrate a View with a Spaces-driven site without needing to maintain an override.

Instead, you can maintain an _alter hook implementation, which I feel is a better approach. Of course, if the View is one you’ve created yourself, build it to your needs. If, on the other hand, you are trying to incorporate someone else’s maintained module or feature into your site, modifying the View is not that different in principle from hacking core.

  • reply

Similar Posts

  • Kicking Off OG Privacy
  • Spaces Integrating a CCK Field
  • Integrating Some Other Feature with Spaces
  • Changing Node Group Audience
  • Simple Spaces Recipe for a Static Welcome Widget

Monthly archive

  • September 2010 (1)
  • August 2010 (2)
  • July 2010 (2)
  • June 2010 (6)
  • May 2010 (9)
more

Feeds

  • Syndicate contentHeadlines
  • Syndicate contentDrupal Planet
  • Syndicate contentAtrium Headlines

casetracker cck drupal features features-servers FL3 freelinking module og openatrium permissions spaces
<all>

© 2009 grayside.org ♠ Glossary ♠ Powered by Drupal ♠ Floating on Archlinux