From 47b2c9665185187b7a8c0f1833e7afde71a48606 Mon Sep 17 00:00:00 2001 From: Herb vd Dool Date: Mon, 7 Nov 2016 09:16:33 -0500 Subject: [PATCH] add a default layout for CiviCRM admin and ability to configure and set to default --- modules/civicrmtheme/civicrmtheme.info | 5 +- modules/civicrmtheme/civicrmtheme.install | 3 +- modules/civicrmtheme/civicrmtheme.module | 25 ++++- .../config/civicrmtheme.settings.json | 5 + .../layout.layout.civicrm_admin_default.json | 89 +++++++++++++++++ .../includes/civicrmtheme.layout.inc | 24 +++++ .../access/civicrmtheme_layout_access.inc | 99 +++++++++++++++++++ 7 files changed, 243 insertions(+), 7 deletions(-) create mode 100755 modules/civicrmtheme/config/civicrmtheme.settings.json create mode 100644 modules/civicrmtheme/config/layout.layout.civicrm_admin_default.json create mode 100644 modules/civicrmtheme/includes/civicrmtheme.layout.inc create mode 100644 modules/civicrmtheme/plugins/access/civicrmtheme_layout_access.inc diff --git a/modules/civicrmtheme/civicrmtheme.info b/modules/civicrmtheme/civicrmtheme.info index ca811d5..77eff8c 100644 --- a/modules/civicrmtheme/civicrmtheme.info +++ b/modules/civicrmtheme/civicrmtheme.info @@ -1,5 +1,5 @@ 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 @@ -7,6 +7,3 @@ package = CiviCRM project = civicrm dependencies[] = civicrm - -files[] = civicrmtheme.module -files[] = civicrmtheme.install diff --git a/modules/civicrmtheme/civicrmtheme.install b/modules/civicrmtheme/civicrmtheme.install index ff24118..521bfc4 100644 --- a/modules/civicrmtheme/civicrmtheme.install +++ b/modules/civicrmtheme/civicrmtheme.install @@ -53,7 +53,8 @@ function civicrmtheme_install() { * Implementation of hook_uninstall(). */ function civicrmtheme_uninstall() { - + $config = config('layout.layout.civicrm_admin_default'); + $config->delete(); } /** diff --git a/modules/civicrmtheme/civicrmtheme.module b/modules/civicrmtheme/civicrmtheme.module index b7224d3..44345ef 100644 --- a/modules/civicrmtheme/civicrmtheme.module +++ b/modules/civicrmtheme/civicrmtheme.module @@ -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. */ @@ -148,4 +170,3 @@ function civicrmtheme_custom_theme() { return $admin_theme; } } - diff --git a/modules/civicrmtheme/config/civicrmtheme.settings.json b/modules/civicrmtheme/config/civicrmtheme.settings.json new file mode 100755 index 0000000..799d609 --- /dev/null +++ b/modules/civicrmtheme/config/civicrmtheme.settings.json @@ -0,0 +1,5 @@ +{ + "_config_name": "civicrmtheme.settings", + "theme_admin": "seven", + "theme_public": "0" +} diff --git a/modules/civicrmtheme/config/layout.layout.civicrm_admin_default.json b/modules/civicrmtheme/config/layout.layout.civicrm_admin_default.json new file mode 100644 index 0000000..84d00d4 --- /dev/null +++ b/modules/civicrmtheme/config/layout.layout.civicrm_admin_default.json @@ -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" + } + } + } + ] +} diff --git a/modules/civicrmtheme/includes/civicrmtheme.layout.inc b/modules/civicrmtheme/includes/civicrmtheme.layout.inc new file mode 100644 index 0000000..610cbfe --- /dev/null +++ b/modules/civicrmtheme/includes/civicrmtheme.layout.inc @@ -0,0 +1,24 @@ + 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); + } +} diff --git a/modules/civicrmtheme/plugins/access/civicrmtheme_layout_access.inc b/modules/civicrmtheme/plugins/access/civicrmtheme_layout_access.inc new file mode 100644 index 0000000..b199f1c --- /dev/null +++ b/modules/civicrmtheme/plugins/access/civicrmtheme_layout_access.inc @@ -0,0 +1,99 @@ +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'])); + } +}