Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #118. Add layout plugins for OG #119

Merged
merged 4 commits into from
May 27, 2022
Merged
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
49 changes: 49 additions & 0 deletions includes/og.layout.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/**
* @file
* Contains layout hook implementations provided by OG.
*/

/**
* Implements hook_layout_access_info().
*/
function og_layout_access_info() {
$info['og_node_group'] = array(
'title' => t("OG: Node is an OG group"),
'description' => t('Control access by whether or not a node is of type "Group".'),
'class' => 'OgNodeGroupLayoutAccess',
'required contexts' => array(
'node' => 'node',
),
);
$info['og_node_group_content'] = array(
'title' => t("OG: Node is an OG group content"),
'description' => t('Control access by whether or not a node is of type "Group content".'),
'class' => 'OgNodeGroupContentLayoutAccess',
'required contexts' => array(
'node' => 'node',)
);

$info['og_member'] = array(
'title' => t("OG: User membership in group"),
'description' => t('Control access by group membership.'),
'class' => 'OgMemberLayoutAccess',
'default' => array('state' => OG_STATE_ACTIVE),
'required contexts' => array(
'node' => 'node',
'user' => 'user',
),
);

$info['og_perm'] = array(
'title' => t("OG: User permission in group"),
'description' => t('Control access by group permission string.'),
'class' => 'OgPermLayoutAccess',
'required contexts' => array(
'node' => 'node',
'user' => 'user',
),
);

return $info;
}
27 changes: 27 additions & 0 deletions og.module
Original file line number Diff line number Diff line change
Expand Up @@ -3880,9 +3880,36 @@ function og_autoload_info() {
'OgBehaviorHandler' => 'plugins/entityreference/behavior/OgBehaviorHandler.class.php',
'OgWidgetHandler' => 'plugins/entityreference/behavior/OgWidgetHandler.class.php',
'OgSelectionHandler' => 'plugins/entityreference/selection/OgSelectionHandler.class.php',
'OgNodeGroupLayoutAccess' => 'plugins/access/OgNodeGroupLayoutAccess.class.php',
'OgMemberLayoutAccess' => 'plugins/access/OgMemberLayoutAccess.class.php',
'OgPermLayoutAccess' => 'plugins/access/OgPermLayoutAccess.class.php',
'OgNodeGroupContentLayoutAccess' => 'plugins/access/OgNodeGroupContentLayoutAccess.class.php',
'OgNodeCreateLinks' => 'plugins/blocks/OgNodeCreateLinks.class.php',
'og_context' => 'includes/og_context.inc',
'og_context_required' => 'includes/og_context.inc',
'og_context_optional' => 'includes/og_context.inc',
'OgTestBase' => 'tests/og.test',
);
}

/**
* Implements hook_layout_api().
*/
function og_layout_api() {
return array(
'file' => 'includes/og.layout.inc',
);
}

/**
* Implements hook_block_info().
*/
function og_block_info() {
$info['node_create_links'] = array(
'info' => t('Content create links'),
'description' => t('Crafted links to create content (nodes) for a given group. REQUIRES the module Entity Reference Prepopulate to work.'),
'required contexts' => array('node' => 'node'),
'class' => 'OgNodeCreateLinks',
);
return $info;
}
65 changes: 4 additions & 61 deletions og.og.inc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
* @file
* Organic Groups plugins declarations.
*
* NOTE: This file is never called in Backdrop. It's here to provide a place to
* store old ctools plugins that are not yet incorporated in Backdrop OG.
* At the moment, the last one to be ported is og_membership_from_group_and_user
*/

/**
Expand All @@ -13,50 +16,6 @@

function og_og_info() {
$info = array(
'access' => array(
'og_is_node_group_content' => array(
'title' => t("OG: Node is an OG group content"),
'description' => t('Control access by whether or not a node is of type "Group content".'),
'callback' => 'og_is_node_group_content_check',
'summary' => 'og_is_node_group_content_summary',
'required context' => new og_context_required(t('Node'), 'node'),
'file' => 'plugins/access/og_is_node_group_content.inc',
),
'og_is_node_group' => array(
'title' => t("OG: Node is an OG group"),
'description' => t('Control access by whether or not a node is of type "Group".'),
'callback' => 'og_is_node_group_check',
'summary' => 'og_is_node_group_summary',
'required context' => new og_context_required(t('Node'), 'node'),
'file' => 'plugins/access/og_is_node_group.inc',
),
'og_member' => array(
'title' => t("OG: user membership in group"),
'description' => t('Control access by group membership.'),
'callback' => 'og_member_access_check',
'default' => array('state' => OG_STATE_ACTIVE),
'settings form' => 'og_member_access_settings',
'summary' => 'og_member_access_summary',
'required context' => array(
new og_context_required(t('User'), 'user'),
new og_context_required(t('Node'), 'node'),
),
'file' => 'plugins/access/og_member.inc',
),
'og_perm' => array(
'title' => t("OG: user permission in group"),
'description' => t('Control access by group permission string.'),
'callback' => 'og_perm_access_check',
'default' => array('perm' => ''),
'settings form' => 'og_perm_access_settings',
'summary' => 'og_perm_access_summary',
'required context' => array(
new og_context_required(t('User'), 'user'),
new og_context_required(t('Node'), 'node'),
),
'file' => 'plugins/access/og_perm.inc',
),
),
'relationships' => array(
'og_membership_from_group_and_user' => array(
'title' => t('OG membership from a group node and user'),
Expand All @@ -72,21 +31,5 @@ function og_og_info() {
),
);

if (module_exists('entityreference_prepopulate')) {
$info['content_types'] = array(
'node_create_links' => array(
'title' => t('Content create links'),
'description' => t('Crafted links to create content (nodes) for a given group.'),
'required context' => new og_context_required(t('Node'), 'node'),
'category' => t('Organic groups'),
'defaults' => array(
'types' => array(),
'field_name' => OG_AUDIENCE_FIELD,
),
'file' => 'plugins/content_types/node_create_links.inc',
),
);
}

return $info;
}
}
77 changes: 77 additions & 0 deletions plugins/access/OgMemberLayoutAccess.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php
/**
* @file
* Plugin to provide access control based upon OG group status.
*/

class OgMemberLayoutAccess extends LayoutAccessNegatable {

/**
* Constructor for a Layout membership in group rule.
*/
function __construct($plugin_name, array $data = array()) {
parent::__construct($plugin_name, $data);
$this->settings += array(
'state' => array(),
);
}

/**
* {@inheritdoc}
*/
function form(&$form, &$form_state) {
parent::form($form, $form_state);
$form['state'] = array(
'#type' => 'select',
'#options' => og_group_content_states(),
'#title' => t('State in group'),
'#multiple' => TRUE,
'#default_value' => $this->settings['state'],
'#description' => t('Only users with the specified state in group will be able to access this.'),
'#required' => TRUE,
);

return $form;
}

/**
* {@inheritdoc}
*/
function checkAccess() {
$user_context = $this->contexts['user'];
$node_context = $this->contexts['node'];
if (empty($user_context) || empty($user_context->data)) {
return;
}

if (empty($node_context) || empty($node_context->data)) {
return;
}

$account = clone $user_context->data;
$node = $node_context->data;
if ($this->settings['negate']) {
return !og_is_member('node', $node->nid, 'user', $account, $this->settings['state']);
}
else {
return og_is_member('node', $node->nid, 'user', $account, $this->settings['state']);
}
}

/**
* {@inheritdoc}
*/
function summary() {
if (empty($this->settings['state'])) {
return t('Error, unset state');
}

$states = og_group_content_states();
$state = array();
foreach ($this->settings['state'] as $value) {
$state[] = $states[$value];
}

return $this->settings['negate'] ? t('User does not have "@state" state in group.', array('@state' => implode(', ', $state),)) : t('User has "@state" state in group.', array('@state' => implode(', ', $state),));
}
}
44 changes: 44 additions & 0 deletions plugins/access/OgNodeGroupContentLayoutAccess.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
/**
* @file
* Plugin to provide access control based upon OG group status.
*/

class OgNodeGroupContentLayoutAccess extends LayoutAccessNegatable {
/**
* {@inheritdoc}
*/
function form(&$form, &$form_state) {
parent::form($form, $form_state);
$form['negate'] = array(
'#type' => 'radios',
'#title' => t('Current node is'),
'#options' => array(
0 => t('OG group content node'),
1 => t('Not OG group content node'),
),
'#weight' => 100,
'#default_value' => (int) $this->settings['negate'],
);
}

/**
* {@inheritdoc}
*/
function checkAccess() {
$node = $this->contexts['node']->data;
if ($this->settings['negate']) {
return !og_is_group_content_type('node', $node->type);
}
else {
return og_is_group_content_type('node', $node->type);
}
}

/**
* {@inheritdoc}
*/
function summary() {
return $this->settings['negate'] ? t('Node is not OG group content') : t('Node is OG group content');
}
}
43 changes: 43 additions & 0 deletions plugins/access/OgNodeGroupLayoutAccess.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/**
* @file
* Plugin to provide access control based upon role membership.
*/
class OgNodeGroupLayoutAccess extends LayoutAccessNegatable {
/**
* {@inheritdoc}
*/
function form(&$form, &$form_state) {
parent::form($form, $form_state);
$form['negate'] = array(
'#type' => 'radios',
'#title' => t('Current node is'),
'#options' => array(
0 => t('OG group node'),
1 => t('Not OG group node'),
),
'#weight' => 100,
'#default_value' => (int) $this->settings['negate'],
);
}

/**
* {@inheritdoc}
*/
function checkAccess() {
$node = $this->contexts['node']->data;
if ($this->settings['negate']) {
return !og_is_group('node', $node);
}
else {
return og_is_group('node', $node);
}
}

/**
* {@inheritdoc}
*/
function summary() {
return $this->settings['negate'] ? t('Node is not an OG group') : t('Node is an OG group');
}
}
Loading