Commit 99dfaacc authored by git's avatar git Committed by slashrsm

Issue #2703639 by sanja_m, slashrsm, Berdir, CTaPByK: Remove crm_core_ui.

parent ce757cf7
......@@ -9,3 +9,9 @@ crm_core.overview:
parent: system.admin
description: 'CRM Core Overview. Manage Contacts, Activites and Relations.'
title: 'CRM Core'
crm_core.config:
route_name: crm_core.config
parent: system.admin_config_system
title: 'CRM Core'
description: 'CRM Core module and feature settings.'
......@@ -13,3 +13,11 @@ crm_core.overview:
_title: 'CRM Core'
requirements:
_custom_access: '\Drupal\crm_core\Access\CRMCoreAccess::access'
crm_core.config:
path: '/admin/config/crm-core'
defaults:
_controller: '\Drupal\system\Controller\SystemController::systemAdminMenuBlockPage'
_title: 'CRM Core'
requirements:
_permission: 'access administration pages'
name: CRM Core UI
type: module
description: 'User Interface for CRM Core.'
package: CRM Core
version: 8.x-1.x-dev
core: 8.x
configure: crm_core.config
dependencies:
# Core Dependencies
- menu_ui
- crm_core
- block
crm_core.config:
route_name: crm_core.config
parent: system.admin_config
title: 'CRM Core'
description: 'CRM Core module and feature settings.'
<?php
use Drupal\Core\Url;
use Drupal\views\ViewExecutable;
/**
* Implements hook_menu().
*/
function crm_core_ui_menu() {
$items = array();
$dashboard_enabled = variable_get('crm_core_dashboard_enabled', FALSE);
if ($dashboard_enabled) {
$items['crm-core/dashboard'] = array(
'title' => 'Dashboard',
'weight' => -10,
'type' => MENU_DEFAULT_LOCAL_TASK,
'context' => MENU_CONTEXT_PAGE,
);
}
$items['admin/config/crm-core'] = array(
'title' => 'CRM Core',
'description' => 'CRM Core module and feature settings.',
'position' => 'right',
'page callback' => 'system_admin_menu_block_page',
'access arguments' => array('access administration pages'),
'file' => 'system.admin.inc',
'file path' => drupal_get_path('module', 'system'),
);
$items['admin/config/crm-core/settings'] = array(
'title' => 'CRM Core Settings',
'description' => 'Configure the appearance of CRM Core and presets for interacting with contacts.',
'page callback' => 'drupal_get_form',
'page arguments' => array('crm_core_ui_admin_config_form'),
'access arguments' => array('administer crm-core settings'),
'file' => 'pages/crm_core_ui.pages.inc',
);
return $items;
}
/**
* Implements hook_permission().
*/
function crm_core_ui_permission() {
return array(
'view crm dashboard' => array(
'title' => t('View CRM dashboard'),
'description' => t('Use dashboard.'),
),
'administer crm-core settings' => array(
'title' => t('Administer CRM Core Settings'),
'restrict access' => TRUE,
),
);
}
/**
* Implements hook_admin_paths().
*/
function crm_core_ui_admin_paths() {
$paths = array(
'crm-core/admin' => TRUE,
'crm-core/admin/*' => TRUE,
);
return $paths;
}
/**
* Render CRM Core Dashboard, if configured, otherwise redirects to contacts list.
*/
function crm_core_ui_dashboard() {
if (variable_get('crm_core_dashboard_enabled', FALSE)) {
$dashboard_path = variable_get('crm_core_dashboard_path', '');
// Get the content for the path.
$output = menu_execute_active_handler($dashboard_path, FALSE);
// Lets check if specified path still exists and accessible.
if ($output === MENU_NOT_FOUND || $output === MENU_ACCESS_DENIED) {
if (user_access('administer crm-core settings')) {
drupal_set_message(t('The dashboard cannot be loaded. Please check the !settings.',
array(
'!settings' => l(t('CRM Core Dashboard settings'), 'admin/config/crm-core/settings'),
)
), 'error');
}
drupal_flush_all_caches();
drupal_goto('crm-core/contact');
}
// If the callback returns an array instead of text, render it.
if (is_array($output)) {
$output = drupal_render($output);
}
$menu_item = menu_get_item($dashboard_path);
if (!empty($menu_item['title'])) {
drupal_set_title($menu_item['title']);
}
return $output;
}
else {
// Dashboard is not configured.
if (user_access('administer crm-core settings')) {
drupal_set_message(t('No dashboard has been configured for CRM Core. Click !here to configure a dashboard.',
array(
'!here' => l(t('here'), 'admin/config/crm-core/settings'),
)
));
}
drupal_flush_all_caches();
drupal_goto('crm-core/contact');
}
}
/**
* Implements hook_views_pre_render()
*/
function crm_core_ui_views_pre_render(ViewExecutable $view) {
if ($view->storage->id() == 'crm_activities_by_contact') {
// @todo Add appropriate replacement or remove.
// crm_core_ui_ctools_add_dropbutton_files();
}
}
/**
* Additional function that adds special CSS/JS files for dropbuttons
*/
function crm_core_ui_ctools_add_dropbutton_files() {
// Add needed files
ctools_add_js('dropbutton');
ctools_add_css('dropbutton');
ctools_add_css('button');
// Add views & seven files
views_add_css('views-admin');
views_add_css('views-admin.ctools');
views_add_css('views-admin.seven');
}
/**
* Contains custom menu definitions of CRM Core.
*
* @return array
* Assoc array of menu items, keyed by menu name.
*/
function crm_core_ui_get_menus() {
$t = get_t();
return array(
'crm-core-menu' => array(
'menu_name' => 'crm-core-menu',
'title' => $t('CRM Core'),
'description' => $t('Provides access to various features and functions within CRM Core.'),
),
'crm-core-admin-menu' => array(
'menu_name' => 'crm-core-admin-menu',
'title' => $t('CRM Core Admin Menu'),
'description' => $t('Provides access to various settings and configuration within CRM Core.'),
)
);
}
/**
* Helper function to remove links by path from specified menu.
*
* @param $conditions
* Assoc array keyed by menu name. Each entry is array of paths, link to which should be removed.
*/
function crm_core_ui_remove_links($conditions) {
foreach ($conditions as $menu_name => $links_path) {
$links = menu_load_links($menu_name);
foreach ($links as $link) {
foreach ($links_path as $link_path) {
if ($link['link_path'] == $link_path) {
menu_link_delete($link['mlid']);
}
}
}
}
}
/**
* Helper function to set theme to use for CRM Core pages.
*
* @return theme_name|NULL
* Machine theme name or NULL if not set.
*/
function crm_core_ui_get_theme() {
if (variable_get('crm_core_theme_enabled', FALSE)) {
return variable_get('crm_core_theme', '');
}
}
function crm_core_ui_preprocess_page(&$variables) {
// Replace "main-menu" links with links from "crm-core-menu".
// This brakes already ported code.
// @todo Add appropriate replacement or remove.
// if (menu_get_custom_theme() && variable_get('crm_core_theme_replace_links', FALSE)) {
// $variables['main_menu'] = menu_navigation_links('crm-core-menu');
// }
}
crm_core.config:
path: '/admin/config/crm-core'
defaults:
_controller: '\Drupal\system\Controller\SystemController::systemAdminMenuBlockPage'
_title: 'CRM Core'
requirements:
_permission: 'access administration pages'
<?php
class DashboardTestCase extends DrupalWebTestCase {
protected $privileged_user;
public static function getInfo() {
return array(
'name' => 'CRM Core UI Dashboard',
'description' => 'Ensure that CRM Core Dashboard working properly.',
'group' => 'CRM Core',
);
}
public function setUp() {
parent::setUp(array('crm_core_ui'));
$this->privileged_user = $this->drupalCreateUser(array(
'view crm dashboard',
'administer crm-core settings',
));
$this->drupalLogin($this->privileged_user);
}
public function testCRMCoreDashboardSettings() {
$config_path = 'admin/config/crm-core/settings';
$checkbox = 'crm_core_dashboard_enabled';
$path_input = 'crm_core_dashboard_path';
$save = 'Save configuration';
$this->drupalGet($config_path);
$this->assertText('Use a Dashboard for CRM Core?', 'Enable Dashboard label is present on the page.');
$this->assertText('Path to Dashboard', 'Path to Dashboard label is present on the page.');
$this->assertField($checkbox, 'Enable Dashboard checkbox is present on the page.');
$this->assertField($path_input, 'Path to Dashboard input is present on the page.');
$this->drupalPost($config_path, array($checkbox => TRUE), $save);
$this->assertText('You must enter VALID path(it must exist already).', 'Empty path is not allowed.');
$this->drupalPost($config_path, array($checkbox => TRUE, $path_input => $this->randomName()), $save);
$this->assertText('You must enter VALID path(it must exist already).', 'Invalid path is not allowed.');
$this->drupalGet('<front>');
$this->assertNoLink('Dashboard', 'No link to Dashboard present.');
$this->drupalPost($config_path, array($checkbox => TRUE, $path_input => 'node'), $save);
$this->assertText('The configuration options have been saved.', 'Valid path OK.');
$this->drupalGet('<front>');
$this->assertLink('Dashboard', 0, 'Link to Dashboard present.');
$this->drupalGet('crm-core/dashboard');
$this->assertText('No front page content has been created yet.', 'Dashboard link working.');
// Emulate deleted Dashboard.
variable_set('crm_core_dashboard_path', 'node1');
$this->clickLink('Dashboard');
$text = 'The dashboard cannot be loaded. Please check the CRM Core Dashboard settings.';
$this->assertText($text, 'Dashboard gracefully handles broken config.');
$this->assertUrl('crm-core/contact', array(),'Dashboard gracefully handles broken config and redirect user correctly.');
}
}
<?php
use Drupal\Core\Form\FormStateInterface;
/**
* Form constructor for the CRM Core configuration form.
*/
function crm_core_ui_admin_config_form($form, FormStateInterface $form_state) {
$form = array();
$form['dashboard'] = array(
'#type' => 'fieldset',
'#title' => t('Dashboard'),
'#weight' => -1,
);
$dashboard_enable_description = 'When checked, this will direct users to the specified dashboard when accessing '
. 'the main link to CRM Core. When unchecked, it will direct users to the main list of contacts in CRM Core. '
. 'Useful in situations where important information about contacts needs to be available at a glance. Use panels,'
. ' homebox or some other tool to create the dashboard, and include the path to the dashboard in the box below.';
$form['dashboard']['crm_core_dashboard_enabled'] = array(
'#type' => 'checkbox',
'#title' => t('Use a Dashboard for CRM Core?'),
'#description' => t($dashboard_enable_description),
'#default_value' => variable_get('crm_core_dashboard_enabled', FALSE),
'#weight' => 0,
);
$form['dashboard']['crm_core_dashboard_path'] = array(
'#type' => 'textfield',
'#title' => t('Path to Dashboard'),
'#default_value' => variable_get('crm_core_dashboard_path', ''),
'#weight' => 1,
'#states' => array(
'visible' => array(
':input[name="crm_core_dashboard_enabled"]' => array('checked' => TRUE),
),
'required' => array(
':input[name="crm_core_dashboard_enabled"]' => array('checked' => TRUE),
),
),
);
$form['theme'] = array(
'#type' => 'fieldset',
'#title' => t('CRM Core Theme'),
'#weight' => 1,
);
$form['theme']['crm_core_theme_enabled'] = array(
'#type' => 'checkbox',
'#title' => t('Use a different theme for CRM Core?'),
'#description' => t('When checked, all pages under the crm-core path will be displayed using a specified theme.'),
'#default_value' => variable_get('crm_core_theme_enabled', FALSE),
'#weight' => 0,
);
$form['theme']['crm_core_theme_settings'] = array(
'#type' => 'fieldset',
'#title' => t('CRM Core Theme settings'),
'#weight' => 1,
'#states' => array(
'visible' => array(
':input[name="crm_core_theme_enabled"]' => array('checked' => TRUE),
),
),
);
// Prepare options for theme select element.
$themes_list = list_themes();
$options = array();
foreach ($themes_list as $name => $theme_description) {
$options[$name] = $theme_description->info['name'];
}
$form['theme']['crm_core_theme_settings']['crm_core_theme'] = array(
'#type' => 'select',
'#title' => t('Select theme to use'),
'#default_value' => variable_get('crm_core_theme', ''),
'#options' => $options,
'#weight' => 0,
'#empty_option' => t('- Please Select -'),
'#empty_value' => '',
'#states' => array(
'required' => array(
':input[name="crm_core_theme_enabled"]' => array('checked' => TRUE),
),
),
);
$links_description = 'When checked, this allows you to use the CRM Core menu as the primary links for the site,' .
' when viewing a page in CRM Core.';
$form['theme']['crm_core_theme_settings']['crm_core_theme_replace_links'] = array(
'#type' => 'checkbox',
'#title' => t('Replace primary links with the CRM Core menu?'),
'#description' => t($links_description),
'#default_value' => variable_get('crm_core_theme_replace_links', FALSE),
'#weight' => 1,
);
$form['theme']['crm_core_theme_settings']['notes_container'] = array(
'#type' => 'container',
'#weight' => 2,
);
$form['theme']['crm_core_theme_settings']['notes_container']['notes'] = array(
'#type' => 'item',
'#markup' => t('Additional settings can be configured within the !theme_settings page.', array(
'!theme_settings' => l(t('theme settings'), 'admin/appearance/settings'),
)),
);
$form['#submit'][] = 'crm_core_ui_admin_config_form_submit';
return system_settings_form($form);
}
/**
* Validate CRM Core settings.
*/
function crm_core_ui_admin_config_form_validate($form, FormStateInterface $form_state) {
// Dashboard path validation.
$dashboard_enabled = $form_state->getValue('crm_core_dashboard_enabled');
if ($dashboard_enabled) {
$menu_item = menu_get_item($form_state->getValue('crm_core_dashboard_path'));
if (!$menu_item) {
form_set_error('crm_core_dashboard_path', t('You must enter VALID path(it must exist already).'));
}
}
// Theme settings validation.
$theme_enabled = $form_state->getValue('crm_core_theme_enabled');
$theme = $form_state->getValue('crm_core_theme');
if ($theme_enabled && empty($theme)) {
form_set_error('crm_core_theme', t('You must select a theme to use.'));
}
}
/**
* Submit handler for CRM Core settings form.
*/
function crm_core_ui_admin_config_form_submit($form, FormStateInterface $form_state) {
$dashboard_enabled_current = $form_state->getValue('crm_core_dashboard_enabled');
$dashboard_enabled_saved = variable_get('crm_core_dashboard_enabled', FALSE);
if ($dashboard_enabled_current && !$dashboard_enabled_saved) {
$item = array(
'link_path' => 'crm-core/dashboard',
'link_title' => 'Dashboard',
'menu_name' => 'crm-core-menu',
'weight' => 0,
);
menu_link_save($item);
variable_set('crm_core_dashboard_enabled', TRUE);
}
elseif (!$dashboard_enabled_current) {
$links = menu_load_links('crm-core-menu');
foreach ($links as $link) {
if ($link['link_path'] == 'crm-core/dashboard') {
menu_link_delete($link['mlid']);
}
}
variable_set('crm_core_dashboard_enabled', FALSE);
}
menu_rebuild();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment