In create content form , node don't have nid and i can't pass it to acl_edit_form.

Comments

salvis’s picture

Status: Active » Postponed (maintainer needs more info)

What path (url) are you referring to?

dvinegla’s picture

i'm trying to show the acl_edit_form ie www.example.com/node/add/story but i can't pass the acl_id to acl_edit_form because the node is not yet created and don't have nid

this is mi path to content_access.module to alow show the acl_edit_form in node creation form

function content_access_form_alter($form_id, &$form){
	if (isset($form['#node']) && $form_id == $form['#node']->type .'_node_form') {
		if (content_access_get_settings('per_node', $form['#node']->type)) {
			content_access_form_access($form);
		}
	}
}

function content_access_form_access(&$form) {
	$node=$form['#node'];
	//apply per node settings if necessary
	
 // --------------  

	if (module_exists('acl')) {
		$form['content_access']['acl'] = array(
      '#type' => 'fieldset', 
      '#title' => t('User access control lists'),
      '#description' => t('These settings allow you to grant access to specific users.'),
      '#collapsible' => TRUE,
      '#tree' => TRUE,
		);
		foreach (array('view', 'update', 'delete') as $op) {
			if(isset($node->nid)){
				$acl_id = acl_get_id_by_name('content_access', $op .'_'. $node->nid);
				if (!$acl_id) { // create one
					$acl_id = acl_create_new_acl('content_access', $op .'_'. $node->nid);
					acl_node_add_acl($node->nid, $acl_id, $op == 'view', $op == 'update', $op == 'delete');
				}
				$form['content_access']['acl'][$op] = acl_edit_form($acl_id, 'Grant '. $op .' access');
				$form['content_access']['acl'][$op]['#collapsed'] = !isset($_POST['acl'][$op]['add_button']) && !isset($_POST['acl'][$op]['delete_button']);
			}
			else{
                               //the node is new and don't have nid,  $acl_id
                               //acl_edit_form needs to work without acl_id
				$form['content_access']['acl'][$op] = acl_edit_form('', 'Grant '. $op .' access', true);
				$form['content_access']['acl'][$op]['#collapsed'] = !isset($_POST['acl'][$op]['add_button']) && !isset($_POST['acl'][$op]['delete_button']);
			}
		}
	}
}


function content_access_nodeapi(&$node, $op, $teaser, $page) {
	switch($op){
                  //-----------
		case 'insert':
		case 'update':
			if (content_access_get_settings('per_node', $node->type)) {
				content_access_update($node);
			}
			break;
	}
}

function content_access_update($node){

	$settings = array();
	foreach (array('view', 'update', 'delete') as $op) {

		if (module_exists('acl') && isset($node->acl)) {
                    
                       //I put the creation of new acl in node insert  bacause in this step, node have nid

			$acl_id = acl_get_id_by_name('content_access', $op .'_'. $node->nid);
			if (!$acl_id) { // create one
				$acl_id = acl_create_new_acl('content_access', $op .'_'. $node->nid);
				acl_node_add_acl($node->nid, $acl_id, $op == 'view', $op == 'update', $op == 'delete');
			}
			$acl= $node->acl[$op];
			$acl['acl_id'] = $acl_id;    //modify the acl_id
			acl_save_form($acl);


		}
	}

      //----------------------
}
salvis’s picture

Please post this as a patch file and indicate what version of Content Access it applies to.

dvinegla’s picture

StatusFileSize
new5.29 KB

Content access version: 5.x-1.3

salvis’s picture

Status: Postponed (maintainer needs more info) » Needs review
StatusFileSize
new1.98 KB

I'm sorry I've taken so long to get back. I had actually written a reply a week ago, but my pc crashed before I had sent it. So I'll try to get this together again...

Here are my comments:

  1. Copy&Paste-and-change-a-little-something is always the easiest strategy for the one who's doing it, but it's hell for those who will need to maintain it later on. Never duplicate code, unless it's absolutely necessary!
  2. I don't want to hard-code 'new_node' in ACL. The client should supply a string of their own.
  3. Follow the coding guidelines and use the Coder module to verify your code.
  4. Especially never ever use tabs for indenting; change your editor settings accordingly.
  5. Re-rolled.

I'm attaching the result — please check it out.

salvis’s picture

Status: Needs review » Fixed

Committed to the 5.x branch and MAIN.

@dvinegla: I'd recommend cleaning up your Content Access patch before you go over there and talk to the maintainer there.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.