-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from herbdool/layout
Add a default layout for CiviCRM admin and ability to configure/set to default. Issue #15
- Loading branch information
Showing
7 changed files
with
243 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"_config_name": "civicrmtheme.settings", | ||
"theme_admin": "seven", | ||
"theme_public": "0" | ||
} |
89 changes: 89 additions & 0 deletions
89
modules/civicrmtheme/config/layout.layout.civicrm_admin_default.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
99
modules/civicrmtheme/plugins/access/civicrmtheme_layout_access.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'])); | ||
} | ||
} |