Skip to content

Commit

Permalink
Merge pull request #20 from herbdool/layout
Browse files Browse the repository at this point in the history
Add a default layout for CiviCRM admin and ability to configure/set to default. Issue #15
  • Loading branch information
colemanw authored Feb 2, 2017
2 parents 8fe0a59 + 47b2c96 commit 5e43fd6
Show file tree
Hide file tree
Showing 7 changed files with 243 additions and 7 deletions.
5 changes: 1 addition & 4 deletions modules/civicrmtheme/civicrmtheme.info
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
name = CiviCRM Theme
description = Define alternate themes for CiviCRM.
description = Define alternative themes and layouts for CiviCRM.
version = 4.7
backdrop = 1.x
type = module
package = CiviCRM
project = civicrm

dependencies[] = civicrm

files[] = civicrmtheme.module
files[] = civicrmtheme.install
3 changes: 2 additions & 1 deletion modules/civicrmtheme/civicrmtheme.install
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ function civicrmtheme_install() {
* Implementation of hook_uninstall().
*/
function civicrmtheme_uninstall() {

$config = config('layout.layout.civicrm_admin_default');
$config->delete();
}

/**
Expand Down
25 changes: 23 additions & 2 deletions modules/civicrmtheme/civicrmtheme.module
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,33 @@
function civicrmtheme_config_info() {
$prefixes['civicrmtheme.settings'] = array(
'label' => t('CiviCRM Theme settings'),
'group' => t('CiviCRM'),
'group' => t('Configuration'),
);
$prefixes['layout.layout.civicrm_admin_default'] = array(
'label' => t('CiviCRM Default Layout'),
'group' => t('Layouts'),
);
return $prefixes;
}

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

/**
* Implements hook_autoload_info().
*/
function civicrmtheme_autoload_info() {
return array(
'CivicrmLayoutAccess' => 'plugins/access/civicrmtheme_layout_access.inc',
);
}

/**
* Get all available themes.
*/
Expand Down Expand Up @@ -148,4 +170,3 @@ function civicrmtheme_custom_theme() {
return $admin_theme;
}
}

5 changes: 5 additions & 0 deletions modules/civicrmtheme/config/civicrmtheme.settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"_config_name": "civicrmtheme.settings",
"theme_admin": "seven",
"theme_public": "0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{
"_config_name": "layout.layout.civicrm_admin_default",
"path": "civicrm",
"name": "civicrm_admin_default",
"title": "Default CiviCRM Layout",
"description": null,
"module": "civicrmtheme",
"weight": 1,
"storage": 4,
"layout_template": "boxton",
"disabled": false,
"settings": {
"title": "",
"title_display": "none",
"title_block": null
},
"positions": {
"header": [
"55f542fe-0763-453b-ba3e-62677ea559e5"
],
"top": [],
"content": [
"default"
],
"bottom": [],
"footer": []
},
"content": {
"55f542fe-0763-453b-ba3e-62677ea559e5": {
"plugin": "system:breadcrumb",
"data": {
"module": "system",
"delta": "breadcrumb",
"settings": {
"title_display": "default",
"title": "",
"style": "default",
"block_settings": [],
"contexts": []
},
"uuid": "55f542fe-0763-453b-ba3e-62677ea559e5",
"style": {
"plugin": "default",
"data": {
"settings": {
"classes": ""
}
}
}
}
},
"default": {
"plugin": "system:main",
"data": {
"module": "system",
"delta": "main",
"settings": {
"title_display": "default",
"title": "",
"style": "default",
"block_settings": [],
"contexts": []
},
"uuid": "default",
"style": {
"plugin": "default",
"data": {
"settings": {
"classes": ""
}
}
}
}
}
},
"conditions": [
{
"plugin": "civicrm",
"data": {
"settings": {
"civicrm": [
"admin"
],
"load_condition_nojs": "Load condition"
}
}
}
]
}
24 changes: 24 additions & 0 deletions modules/civicrmtheme/includes/civicrmtheme.layout.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

/**
* Implements hook_layout_access_info().
*/
function civicrmtheme_layout_access_info() {
$info['civicrm'] = array(
'title' => t('CiviCRM pages'),
'description' => t('Control access by the current CiviCRM page.'),
'class' => 'CivicrmLayoutAccess',
);
return $info;
}

/**
* Implements hook_layout_revert().
*/
function civicrmtheme_layout_revert(Layout $old_layout) {
if ($old_layout->name == 'civicrm_admin_default') {
$config = config('layout.layout.' . $old_layout->name);
$config->delete();
config_install_default_config('civicrmtheme', 'layout.layout.' . $old_layout->name);
}
}
99 changes: 99 additions & 0 deletions modules/civicrmtheme/plugins/access/civicrmtheme_layout_access.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php
/**
* @file
* Plugin to provide access control based upon the current site language.
*/

class CivicrmLayoutAccess extends LayoutAccess {
/**
* Constructor for a Layout access rule.
*/
function __construct($plugin_name, array $data = array()) {
parent::__construct($plugin_name, $data);
$this->settings += array(
'civicrm' => array(),
);
}

/**
* {@inheritdoc}
*/
function summary() {
$civicrm = array(
'admin' => t('Admin'),
'public' => t('Public')
);
$names = array();
foreach ($this->settings['civicrm'] as $civi) {
$names[] = $civicrm[$civi];
}
if (empty($names)) {
return t('No CiviCRM pages');
}
return format_plural(count($names), 'CiviCRM pages are "@civicrm"', 'CiviCRM pages are either "@civicrm"', array('@civicrm' => implode(', ', $names)));
}

/**
* {@inheritdoc}
*/
function checkAccess() {
if (arg(0) != 'civicrm') {
return FALSE;
}
if (arg(1) == 'upgrade' || arg(1) == 'ajax') {
return FALSE;
}
if (!civicrm_initialize()) {
return FALSE;
}

// Get the menu items.
$args = explode('?', $_GET['q']);
$path = $args[0];

// Get the menu for above URL.
$item = CRM_Core_Menu::get($path);

// Check path for public or not and use layout if matches settings
switch(CRM_Utils_Array::value('is_public', $item)) {
case TRUE:
if (in_array('public', $this->settings['civicrm'])) {
return TRUE;
}
break;
case FALSE:
if (in_array('admin', $this->settings['civicrm'])) {
return TRUE;
}
break;
default:
return FALSE;
}
}

/**
* {@inheritdoc}
*/
function form(&$form, &$form_state) {
parent::form($form, $form_state);
$options = array(
'admin' => t('Admin'),
'public' => t('Public')
);
$form['civicrm'] = array(
'#title' => t('CiviCRM pages'),
'#type' => 'checkboxes',
'#options' => $options,
'#description' => t('Pass only if the current CiviCRM page is one of the following types.'),
'#default_value' => $this->settings['civicrm'],
);
}

/**
* {@inheritdoc}
*/
function formSubmit($form, &$form_state) {
parent::formSubmit($form, $form_state);
$this->settings['civicrm'] = array_keys(array_filter($form_state['values']['civicrm']));
}
}

0 comments on commit 5e43fd6

Please sign in to comment.