flexiaccess.nodes.inc in Flexi Access 7
Form handling for per node ACL.
File
flexiaccess.nodes.incView source
<?php
/**
* @file
* Form handling for per node ACL.
*/
/**
* Build form to handle ACLs for node.
*/
function flexiaccess_page($form, &$form_state, $node) {
// Get active content types that have Flexi access managing their ACL.
$types = variable_get('flexiaccess_types', array());
$ntype = $node->type;
if (isset($types[$ntype]) && $types[$ntype] && module_exists('acl')) {
$cnt = _flexiaccess_acl_count($node->nid);
$form_state['node'] = $node;
if (0 == $cnt) {
$form['createacl'] = array(
'#type' => 'markup',
'#markup' => t('<p><strong>Create ACL (Access Control List)</strong></p><p>Currently, there is no ACL for this node. Press “Create ACL” if you want to create one.</p>'),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Create ACL'),
'#submit' => array(
'flexiaccess_create_acl',
),
);
return $form;
}
else {
$form['acl'] = array(
'#type' => 'fieldset',
'#title' => t('User based ACL'),
'#description' => t("Manage individual users' access to this node. Remember to press “Commit updates” when done (otherwise, your changes will not be saved)."),
'#collapsible' => TRUE,
'#tree' => TRUE,
);
$ops = array();
if (user_access('flexiaccess view')) {
$ops[] = 'view';
}
if (user_access('flexiaccess update')) {
$ops[] = 'update';
}
if (user_access('flexiaccess delete')) {
$ops[] = 'delete';
}
foreach ($ops as $op) {
$acl_id = acl_get_id_by_name('flexiaccess', $op . '_' . $node->nid);
$foo = acl_edit_form($form_state, $acl_id, t('Manage !op permission', array(
'!op' => $op,
)));
$form['acl'][$op] = acl_edit_form($form_state, $acl_id, t('!op permission', array(
'!op' => $op,
)));
$form['acl'][$op]['#collapsed'] = !isset($_POST['acl_' . $acl_id]) && !unserialize($form['acl'][$op]['user_list']['#default_value']);
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Commit updates'),
'#weight' => 10,
);
if (user_access('flexiaccess create acl')) {
$form['reset'] = array(
'#type' => 'submit',
'#value' => t('Remove ACLs for this node'),
'#weight' => 11,
'#submit' => array(
'flexiaccess_page_reset',
),
);
}
if (!$node->status) {
drupal_set_message(t("Warning: Your content is not published, but users with permissions shown below have access to it."), 'error');
}
return $form;
}
}
drupal_set_message(t('This content type is not managed by Flexi access.'), 'error');
}
/**
* Commit updates for node form.
*/
function flexiaccess_page_submit($form, &$form_state) {
$node = $form_state['node'];
if (module_exists('acl')) {
foreach (array(
'view',
'update',
'delete',
) as $op) {
if (isset($form_state['values']['acl'][$op])) {
acl_save_form($form_state['values']['acl'][$op]);
}
}
}
// Apply new settings.
node_access_acquire_grants($node);
cache_clear_all();
drupal_set_message(t('Your changes to the ACL has been saved.'));
}
/**
* Create an ACL for the node.
*/
function flexiaccess_create_acl($form, &$form_state) {
$node = $form_state['node'];
_flexiaccess_create_acl_rows($node->nid);
// Apply new settings.
node_access_acquire_grants($node, TRUE);
cache_clear_all();
drupal_set_message(t('An ACL for the node has been created.'));
}
/**
* Clear all ACLs for current node.
*/
function flexiaccess_page_reset($form, &$form_state) {
$node = $form_state['node'];
acl_node_clear_acls($node->nid, 'flexiaccess');
// Apply new settings.
node_access_acquire_grants($node, TRUE);
cache_clear_all();
drupal_set_message(t('The ACLs list for the node has been removed.'));
}
Functions
Name![]() |
Description |
---|---|
flexiaccess_create_acl | Create an ACL for the node. |
flexiaccess_page | Build form to handle ACLs for node. |
flexiaccess_page_reset | Clear all ACLs for current node. |
flexiaccess_page_submit | Commit updates for node form. |