Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion og_content_types/og_content_types.admin.inc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function og_content_types_admin_form($form, &$form_state) {
$options = array();
$fields = field_info_instances('node', $key);
foreach ($fields as $name => $field) {
if ($field['widget']['module'] == 'widget_content_types') {
if ($field['widget']['module'] == 'field_content_types') {
$options[$name] = $field['label'];
}
}
Expand Down
56 changes: 35 additions & 21 deletions og_content_types/og_content_types.module
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ function og_content_types_menu() {
* Implement hook_form_alter().
*/
function og_content_types_form_alter(&$form, &$form_state, $form_id) {
if (isset($form['#node']) && $form['#node']->type . '_node_form' == $form_id
&& og_is_group_content_type('node', $form['#node']->type)) {
if (isset($form['#node']->type) && og_is_group_content_type('node', $form['#node']->type)) {

$field =& $form['group_audience'][$form['group_audience']['#language']];

Expand All @@ -55,33 +54,43 @@ function og_content_types_form_alter(&$form, &$form_state, $form_id) {
}
}
}

}
}

/**
* Check if target type of node could be related to certain group
*/
function og_content_types_group_node($gid, $content_type) {
$group_nodes = &drupal_static(__FUNCTION__, array());
$name = $gid .'_'. $content_type;
// try to get node id from group id
if ($node = db_query_range(implode(' ', array(
'SELECT n.nid, n.type FROM {og} o, {node} n',
'WHERE n.nid = o.etid AND o.gid = :gid'
)), 0, 1, array(':gid' => $gid))->fetchObject()) {
// try to get field name
if ($field = variable_get('og_content_types_'. $node->type, 0)) {
// if node type could be created under this group return TRUE
return db_query(implode(' ', array(
'SELECT COUNT(*) FROM {field_data_'. $field .'}',
'WHERE entity_id = :nid AND '. $field .'_value = :type'
)), array(
':nid' => $node->nid, ':type' => $content_type,
))->fetchField()
? TRUE
: FALSE;
if (!isset($group_nodes[$name])) {
if ($node = db_query_range(implode(' ', array(
'SELECT n.nid, n.type FROM {og} o, {node} n',
'WHERE n.nid = o.etid AND o.gid = :gid'
)), 0, 1, array(':gid' => $gid))->fetchObject()) {
// try to get field name
if ($field = variable_get('og_content_types_'. $node->type, 0)) {
// if node type could be created under this group return TRUE
$group_nodes[$name] = db_query(implode(' ', array(
'SELECT COUNT(*) FROM {field_data_'. $field .'}',
'WHERE entity_id = :nid AND '. $field .'_value = :type'
)), array(
':nid' => $node->nid, ':type' => $content_type,
))->fetchField()
? TRUE
: FALSE;

// cache it
}
}
$group_nodes[$name] = isset($group_nodes[$name])
? $group_nodes[$name]
: TRUE;
}
// FALSE :-|
return TRUE;

return $group_nodes[$name];
}

/**
Expand Down Expand Up @@ -122,7 +131,13 @@ function og_content_types_menu_access() {
$node_type = str_replace('-', '_', $args[1]);

if (empty($access_callback) || call_user_func_array($access_callback, $args)) {
if (og_is_group_content_type('node', $node_type) && $groups = db_query(implode(' ', array(

if (variable_get('og_content_types_'. $node_type, 0)
&& og_is_group_type('node', $node_type)) {
return TRUE;
}
if (og_is_group_content_type('node', $node_type)
&& $groups = db_query(implode(' ', array(
"SELECT og.*",
"FROM {og} og, {field_data_group_audience} ga",
"WHERE ga.group_audience_gid = og.gid",
Expand All @@ -135,7 +150,6 @@ function og_content_types_menu_access() {
}
}
}
return TRUE;
}
return FALSE;
}