Grayside.Org

Home

Spaces Integrating a CCK Field

grayside — Mon, 07/26/2010 - 12:25

I wanted to make a CCK Field available only when a given feature was enabled. It turns out it’s really easy.

CCK comes with a hook_field_access() hook (see content_access()). Any implementation of this function that returns FALSE for a given field results in that field being denied to the user.

By implementing this function with a Spaces API call instead of the content_permissions module approach of a new, field-specific permission, all kinds of magic becomes possible.

Read on for demonstration code.

<?php
/**
* Implementation of hook_field_access().
* Allow View/Edit access to 'field_my_cck_field' only when 'feature_name' is enabled.
*/
function custom_field_access($op, $field, $account, $node = NULL) {
 
// Be sure not to affect other fields.
 
if ($field['field_name'] != 'field_my_cck_field') {
    return
TRUE;
  }
 
  switch (
$op) {
    case
'edit':
    case
'view':
     
// Make access contingent on whether a given feature is enabled in the current space, such as atrium_book.
     
return spaces_access_feature('view', 'feature_name');
  }
}
?>

EDIT: Issue posted to the Spaces queue with patch to add this functionality generically for all fields.

  • access control
  • cck
  • openatrium
  • spaces
  • Add new comment

Similar Posts

  • CCK Fields and the Open Atrium Node Form
  • Adding a Content Type to the Open Atrium Calendar Views
  • Adding Items to the Open Atrium Settings Menu
  • Integrating Some Other Feature with Spaces
  • Integrating the Features Server into OpenAtrium

Monthly archive

  • September 2010 (2)
  • 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 FL3 freelinking module og openatrium permissions spaces views
<all>

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