Skip to content

Commit fc7eb4d

Browse files
author
Josh Walker
committed
#123 Backend checks now use drupal_set_message() and output more specific messages.
1 parent 41aa183 commit fc7eb4d

File tree

3 files changed

+113
-49
lines changed

3 files changed

+113
-49
lines changed

includes/config.inc

-39
Original file line numberDiff line numberDiff line change
@@ -71,45 +71,6 @@ function kalatheme_bootstrap_library_form() {
7171
return $form;
7272
}
7373

74-
/**
75-
* Form constructor for Bootstrap library selection form
76-
*
77-
* @return array
78-
*/
79-
function kalatheme_backend_check_form() {
80-
$form = array();
81-
82-
if (isset($_SERVER['PANTHEON_ENVIRONMENT'])) {
83-
$form['pantheon_check'] = array(
84-
'#weight' => -100,
85-
'#prefix' => '<div class="alert alert-info">',
86-
'#markup' => t("You are on Pantheon. <strong>You need to set the connection mode to SFTP</strong> to allow for custom Bootstrap libraries and subtheme generation!"),
87-
'#suffix' => '</div>',
88-
);
89-
}
90-
else {
91-
if (kalatheme_backend_check()) {
92-
$form['backend_check'] = array(
93-
'#weight' => -100,
94-
'#prefix' => '<div class="alert alert-success">',
95-
'#markup' => t("Your webserver is correctly configured to allow for custom Bootstrap libraries and subtheme generation!"),
96-
'#suffix' => '</div>',
97-
);
98-
}
99-
else {
100-
$form['backend_check'] = array(
101-
'#weight' => -100,
102-
'#prefix' => '<div class="alert alert-danger">',
103-
'#markup' => t("If you want Kalatheme to be able to use custom Bootstrap libraries or generate subthemes automatically please properly configure your webserver."),
104-
// @todo add link to docs here
105-
'#suffix' => '</div>',
106-
);
107-
}
108-
}
109-
110-
return $form;
111-
}
112-
11374
/**
11475
* Form constructor for subtheme selection form
11576
*

includes/utils.inc

+112-9
Original file line numberDiff line numberDiff line change
@@ -316,18 +316,121 @@ function kalatheme_use_libraries() {
316316
* True if all good, message if no good
317317
*/
318318
function kalatheme_backend_check() {
319-
// Verify FTP support
320-
$ftp_installed = extension_loaded('ftp');
321-
// Verify SSH support
322-
$ssh_installed = extension_loaded('ssh2');
323-
// Verify web server write permissions
324-
$install_permissions = kalatheme_has_write_access();
325-
// Verify update module is enabled
326-
$updates_module = module_exists('update');
319+
$info = kalatheme_backend_check_info();
320+
$messages = drupal_get_messages(NULL, FALSE);
327321

328-
return (($ftp_installed || $ssh_installed || $install_permissions) && $updates_module);
322+
// Output messages for each of the checks.
323+
foreach ($info as $check) {
324+
if (isset($check['messages']) && !empty($check['messages'])) {
325+
$bool = $check['bool'];
326+
if (isset($check['messages'][$bool])) {
327+
$message = $check['messages'][$bool];
328+
$status = $check['bool'] ? 'status' : 'error';
329+
330+
// Make sure we don't set a message twice.
331+
$already_set = FALSE;
332+
foreach ($messages[$status] as $existing) {
333+
if ($existing == $message) {
334+
$already_set = TRUE;
335+
break;
336+
}
337+
}
338+
339+
if (!$already_set) {
340+
drupal_set_message($message, $status);
341+
}
342+
}
343+
}
344+
}
345+
346+
return ($info['install_permissions'] && $info['updates_module']);
347+
}
348+
349+
/**
350+
* Store and return info about backend features that we might need for Kalatheme
351+
* to work properly.
352+
*/
353+
function kalatheme_backend_check_info(){
354+
$info = array(
355+
// Check if we're on Pantheon.
356+
'pantheon' => array(
357+
'bool' => isset($_SERVER['PANTHEON_ENVIRONMENT']),
358+
'messages' => array(
359+
TRUE => t('You are on Pantheon. !strong_openYou need to set the connection mode to SFTP!strong_close to allow for custom Bootstrap libraries and subtheme generation!', array('!strong_open' => '<strong>', '!strong_close' => '</strong>')),
360+
),
361+
),
362+
// Verify FTP support
363+
'ftp' => array(
364+
'bool' => extension_loaded('ftp'),
365+
'messages' => array(),
366+
),
367+
// Verify SSH support
368+
'ssh' => array(
369+
'bool' => extension_loaded('ssh2'),
370+
'messages' => array(),
371+
),
372+
// Verify web server write permissions
373+
'write_access' => array(
374+
'bool' => kalatheme_has_write_access(),
375+
'messages' => array(
376+
FALSE => t('Your webserver permissions are not configured correctly to facilitate subtheme generation. See !the_wiki for help.', array('!the_wiki' => l('the wiki', 'https://github.com/drupalprojects/kalatheme/wiki/Configuring-Server-for-Automatic-Kalatheme-installation'))),
377+
),
378+
),
379+
// Verify update module is enabled
380+
'updates_module' => array(
381+
'bool' => module_exists('update'),
382+
'messages' => array(
383+
FALSE => t('The Updates module needs be enabled for subtheme generation. Please visit the !modules_page to enable it.', array('!modules_page' => l('modules page', 'admin/modules'))),
384+
),
385+
),
386+
);
387+
388+
// This one is a conglomerate of some of the others.
389+
$info['install_permissions'] = array(
390+
'bool' => $info['ftp']['bool'] || $info['ssh']['bool'] || $info['write_access']['bool'],
391+
'messages' => array(
392+
TRUE => t('Your webserver is correctly configured to allow for custom Bootstrap libraries and subtheme generation!'),
393+
FALSE => t('Kalatheme need FTP, SSH or write access in order to generate a subtheme.'),
394+
),
395+
);
396+
397+
return $info;
329398
}
330399

400+
401+
if (isset($_SERVER['PANTHEON_ENVIRONMENT'])) {
402+
$form['pantheon_check'] = array(
403+
'#weight' => -100,
404+
'#prefix' => '<div class="alert alert-info">',
405+
'#markup' => t("You are on Pantheon. <strong>You need to set the connection mode to SFTP</strong> to allow for custom Bootstrap libraries and subtheme generation!"),
406+
'#suffix' => '</div>',
407+
);
408+
}
409+
else {
410+
if (kalatheme_backend_check()) {
411+
$form['backend_check'] = array(
412+
'#weight' => -100,
413+
'#prefix' => '<div class="alert alert-success">',
414+
'#markup' => t("Your webserver is correctly configured to allow for custom Bootstrap libraries and subtheme generation!"),
415+
'#suffix' => '</div>',
416+
);
417+
}
418+
else {
419+
$form['backend_check'] = array(
420+
'#weight' => -100,
421+
'#prefix' => '<div class="alert alert-danger">',
422+
'#markup' => t("If you want Kalatheme to be able to use custom Bootstrap libraries or generate subthemes automatically please properly configure your webserver."),
423+
// @todo add link to docs here
424+
'#suffix' => '</div>',
425+
);
426+
}
427+
}
428+
429+
430+
431+
432+
433+
331434
/**
332435
* Check whether Kalatheme has write access to libraries and modules directories.
333436
*

theme-settings.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function kalatheme_form_system_theme_settings_alter(&$form, &$form_state) {
3232
}
3333

3434
// Subtheme backend checks
35-
$form = array_merge($form, kalatheme_backend_check_form());
35+
kalatheme_backend_check();
3636

3737
// Kalatheme settings
3838
$form = array_merge($form, kalatheme_bootstrap_library_form());

0 commit comments

Comments
 (0)