Skip to content

Commit 855687c

Browse files
committed
Install profile magic
1 parent d8b1d24 commit 855687c

File tree

4 files changed

+41
-15
lines changed

4 files changed

+41
-15
lines changed

includes/setup.inc

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ define('DEFAULT_FONTAWESOME_URL', 'http://fontawesome.io/./assets/font-awesome-4
1414
* Form for kalatheme setup
1515
*/
1616
function kalatheme_setup_form() {
17-
require_once DRUPAL_ROOT . '/' . drupal_get_path('theme', 'kalatheme') . '/includes/utils.inc';
17+
require_once dirname(__FILE__) . '/utils.inc';
1818

1919
if (_kalatheme_backend_check()) {
2020
$form['backend_check'] = array(
@@ -28,7 +28,7 @@ function kalatheme_setup_form() {
2828
'#prefix' => '<div class="alert alert-danger">',
2929
'#markup' => t("If you want Kalatheme to be able to install and enable your subtheme for you please make sure that both @lib_path and @theme_path exist and are writable. Otherwise it will just give you an archive to download.", array(
3030
'@lib_path' => is_dir('sites/all/libraries') ? 'sites/all/libraries' : 'sites/all',
31-
'@theme_path' => drupal_realpath(substr(drupal_get_path('theme', 'kalatheme'), 0, strrpos(drupal_get_path('theme', 'kalatheme'), '/'))),
31+
'@theme_path' => 'sites/all/themes',
3232
)),
3333
'#suffix' => '</div>',
3434
);
@@ -178,6 +178,28 @@ function kalatheme_setup_form_validate($form, &$form_state) {
178178
* @see kalatheme_setup_form_validate()
179179
*/
180180
function kalatheme_setup_form_submit($form, &$form_state) {
181+
// Build the batch
182+
$batch = kalatheme_setup_batch($form, $form_state);
183+
batch_set($batch);
184+
}
185+
186+
/**
187+
* Form submission handler for kalatheme_setup_form().
188+
*
189+
* Uses BATCH API for file processing and HTTP request stuffs
190+
*
191+
* Uploads the file attached to the form, then attempts to extract the archive
192+
* into a temporary location and verify it. Verifies the archive is a valid
193+
* Bootsrap library and if possible installs the library into the libraries API
194+
* directory. If not saves it for output to the user.
195+
*
196+
* Then builds a subtheme using the name provided and tries to install it. If
197+
* it cannot it grabs the bootstrap library and outputs both as an archive for
198+
* the user to install.
199+
*
200+
* @see kalatheme_setup_form_validate()
201+
*/
202+
function kalatheme_setup_batch($form, &$form_state) {
181203
// Let's begin to define some opps
182204
$operations = array();
183205
$batch = array(
@@ -231,7 +253,8 @@ function kalatheme_setup_form_submit($form, &$form_state) {
231253
$operations[] = array('_kalatheme_dress_you_up', array($machine_name));
232254
// Build the batch and cook it
233255
$batch['operations'] = $operations;
234-
batch_set($batch);
256+
257+
return $batch;
235258
}
236259

237260
/**
@@ -588,7 +611,7 @@ function _kalatheme_dress_you_up($machine_name, &$context) {
588611
}
589612
// Move from temp to legitness or output to the user for DL
590613
$booted = TRUE;
591-
$theme_path = drupal_realpath(substr(drupal_get_path('theme', 'kalatheme'), 0, strrpos(drupal_get_path('theme', 'kalatheme'), '/')));
614+
$theme_path = drupal_realpath('sites/all/themes');
592615
$library_path = drupal_realpath('sites/all/libraries');
593616
$stuff = array(
594617
file_directory_temp() . DIRECTORY_SEPARATOR . $machine_name => $theme_path . DIRECTORY_SEPARATOR . $machine_name,
@@ -700,7 +723,10 @@ function _kalatheme_batch_done($success, $results, $operations) {
700723
// relevant
701724
drupal_set_message(t($results['message']), 'warning', FALSE);
702725
}
703-
drupal_goto('admin/appearance');
726+
// Only redirect if not an install profile
727+
if (isset($GLOBALS['conf']['install_task']) && $GLOBALS['conf']['install_task'] === 'done') {
728+
drupal_goto('admin/appearance');
729+
}
704730
}
705731

706732
/**
@@ -797,7 +823,7 @@ function _kalatheme_bootstrap_preview($form, &$form_state) {
797823
* True if all good, message if no good
798824
*/
799825
function _kalatheme_backend_check() {
800-
$theme_dir = drupal_realpath(substr(drupal_get_path('theme', 'kalatheme'), 0, strrpos(drupal_get_path('theme', 'kalatheme'), '/')));
826+
$theme_dir = 'sites/all/themes';
801827
$libraries_dir = 'sites/all/libraries';
802828
// Create paths if needed
803829
// $theme_path should already exist
@@ -810,7 +836,7 @@ function _kalatheme_backend_check() {
810836
if (!file_prepare_directory($libraries_dir) || !file_prepare_directory($theme_dir)) {
811837
// @todo something
812838
}
813-
return is_writable(drupal_realpath($libraries_dir)) && is_writable($theme_dir);
839+
return is_writable(drupal_realpath($libraries_dir)) && is_writable(drupal_realpath($theme_dir));
814840
}
815841

816842
/**

includes/theme.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ function kalatheme_links__system_main_menu($variables) {
412412
*/
413413
function kalatheme_status_messages($variables) {
414414
// Call correct theme function depending on whether all dependencies loaded.
415-
require_once DRUPAL_ROOT . '/' . drupal_get_path('theme', 'kalatheme') . '/includes/utils.inc';
415+
require_once dirname(__FILE__) . '/utils.inc';
416416
$status_function = _kalatheme_load_dependencies();
417417
return $status_function($variables);
418418
}

template.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@
1313
}
1414

1515
// Load some core things
16-
$kalatheme_path = drupal_get_path('theme', 'kalatheme');
17-
require_once $kalatheme_path . '/includes/theme.inc';
18-
require_once $kalatheme_path . '/includes/libraries.inc';
16+
// Use this instead of drupal_get_path so we can use this
17+
// during an install profile without nuking the world
18+
require_once dirname(__FILE__) . '/includes/theme.inc';
19+
require_once dirname(__FILE__) . '/includes/libraries.inc';
1920
// We need to do this so that our views plugin class will be loaded correctly
2021
// since we cant use the files[] directive in a theme .info file
21-
require_once $kalatheme_path . '/views/plugins/views_plugin_style_grid_bootstrap.inc';
22+
require_once dirname(__FILE__) . '/views/plugins/views_plugin_style_grid_bootstrap.inc';
2223

2324
/**
2425
* Represents the number of columns in the grid supplied by Bootstrap.
@@ -99,7 +100,7 @@ function kalatheme_preprocess_html(&$variables) {
99100
$variables['path_to_kalatheme'] = drupal_get_path('theme', 'kalatheme');
100101

101102
// Load all dependencies.
102-
require_once DRUPAL_ROOT . '/' . $variables['path_to_kalatheme'] . '/includes/utils.inc';
103+
require_once dirname(__FILE__) . '/includes/utils.inc';
103104
_kalatheme_load_dependencies();
104105
}
105106

theme-settings.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ function kalatheme_form_system_theme_settings_alter(&$form, &$form_state) {
2222
// If a non-kalatheme theme is the admin theme we need to
2323
// load this stuff again to get grid size info and not throw
2424
// errors
25-
$kalatheme_path = drupal_get_path('theme', 'kalatheme');
26-
require_once $kalatheme_path . '/includes/libraries.inc';
25+
require_once dirname(__FILE__) . '/includes/libraries.inc';
2726
if (!defined('KALATHEME_BOOTSTRAP_LIBRARY')) {
2827
define('KALATHEME_BOOTSTRAP_LIBRARY', variable_get('theme_default', 'kalatheme') . '_bootstrap');
2928
}

0 commit comments

Comments
 (0)