Idea is to add checkbox field to multigroup called privacy and have 3 checkboxes - private, public, friends. this info is saved with field and will follow group item even if delta changes. then its a matter of css/js to make it apear as settings icons.

can such field be added dynamically? it sure can be added manually and set not to display.

such way you would have full features of your module working properly with multigroups. whats even more awesome, you could check field setting in preprocess function and display nice tokenized message like 'this information is for friends only'.

Comments

henrijs.seso’s picture

actually you would add checkbox field to each set of fields in multigroup.

henrijs.seso’s picture

this function in custom module does the trick. Maybe it is possible to improve this so it could be a candidate for CCK Private Fields module?

Following code works if in multigroup a field field_privacy_profile_position is placed and one of options is 'Follower'. It is possible to hide field field_profile_position from people who are not followers.

function MODULENAME_preprocess_content_field(&$variables) {
	// Check if we are dealing with field that is protected and is about to be rendered in teaser or page.
	if ($variables['field_name'] == 'field_profile_position' && ($variables['teaser'] || $variables['page'])) {
		foreach($variables['items'] as $key => $item) {
			// Find delta.
			$delta = $item['#delta'];
			// Check settings of access field for that delta.
			if($variables['element']['#node']->field_privacy_profile_position[$delta]['value'] == 'Followers') {
				// Insert check if user is one in f. ex. follower category.
				$variables['items'][$key]['view'] = 'Insert access denied tokenized message here...';
			}
		}
	}
}

Markus, do you think such approach could be used? Is it safe enough to do things like this in preprocess function?

henrijs.seso’s picture

here are updated function that properly removes field from display without messages or leaving trace, messages will probably just encourage hacking :)

function MODULENAME_preprocess_content_field(&$variables) {
	// Array with privacy field and protected fields.
	// This could be sniffed out from $variables['element']['#node'] and
	// no manual labour would be required. Just look for group with field that
	// ends with _privacy and you get privacy field and the rest of fields are
	// protected.
	$fields['field_profile_contact_privacy'] = array(
		'field_profile_contact_value',
		'field_profile_contact_label',
		'field_profile_contact_type',
	);
	foreach($fields as $privacy_field => $protected_fields) {
		// Check if we are dealing with field that is protected and is about to be rendered in teaser or page.
		if (in_array($variables['field_name'], $protected_fields) && ($variables['teaser'] || $variables['page'])) {
			foreach($variables['items'] as $key => $item) {
				$delta = $item['#delta'];
				$roles = og_user_roles_get_roles_by_group($variables['element']['#node']->nid, $GLOBALS['user']->uid);
				$allowed = $variables['element']['#node']->{$privacy_field}[$delta]['value'];
				if ($allowed != 'Followers') { // Some test check.
					$variables['field_empty'] = TRUE;
				}
			}
		}
	}
}