本文整理汇总了PHP中drupal_get_profile函数的典型用法代码示例。如果您正苦于以下问题:PHP drupal_get_profile函数的具体用法?PHP drupal_get_profile怎么用?PHP drupal_get_profile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了drupal_get_profile函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, $bundle_name = NULL) {
$this->currentBundle = $this->assigner->loadBundle($bundle_name);
$settings = $this->currentBundle->getAssignmentSettings(self::METHOD_ID);
$this->setTypeSelect($form, $settings['types'], $this->t('exclude'));
$module_settings = $settings['module'];
$curated_settings = $settings['curated'];
$form['curated'] = array(
'#type' => 'checkbox',
'#title' => t('Exclude designated site-specific configuration'),
'#default_value' => $curated_settings,
'#description' => $this->t('Select this option to exclude from packaging items on a curated list of site-specific configuration.'),
);
$form['module'] = array(
'#type' => 'container',
'#tree' => TRUE,
);
$form['module']['enabled'] = array(
'#type' => 'checkbox',
'#title' => t('Exclude module-provided entity configuration'),
'#default_value' => $module_settings['enabled'],
'#description' => $this->t('Select this option to exclude from packaging any configuration that is provided by already enabled modules. Note that <a href="!url">simple configuration</a> will not be excluded as it is always module-provided.', array('!url' => 'http://www.drupal.org/node/1809490')),
'#attributes' => array(
'data-module-enabled' => 'status',
),
);
$show_if_module_enabled_checked = array(
'visible' => array(
':input[data-module-enabled="status"]' => array('checked' => TRUE),
),
);
$info = system_get_info('module', drupal_get_profile());
$form['module']['profile'] = array(
'#type' => 'checkbox',
'#title' => t("Don't exclude install profile's configuration"),
'#default_value' => $module_settings['profile'],
'#description' => $this->t("Select this option to not exclude from packaging any configuration that is provided by this site's install profile, %profile.", array('%profile' => $info['name'])),
'#states' => $show_if_module_enabled_checked,
);
$machine_name = $this->currentBundle->getMachineName();
$machine_name = !empty($machine_name) ? $machine_name : t('none');
$form['module']['namespace'] = array(
'#type' => 'checkbox',
'#title' => t("Don't exclude configuration by namespace"),
'#default_value' => $module_settings['namespace'],
'#description' => $this->t("Select this option to not exclude from packaging any configuration that is provided by modules with the package namespace (currently %namespace).", array('%namespace' => $machine_name)),
'#states' => $show_if_module_enabled_checked,
);
$this->setActions($form);
return $form;
}
示例2: getAllFolders
/**
* Returns a map of all config object names and their folders.
*
* The list is based on enabled modules and themes. The active configuration
* storage is used rather than \Drupal\Core\Extension\ModuleHandler and
* \Drupal\Core\Extension\ThemeHandler in order to resolve circular
* dependencies between these services and \Drupal\Core\Config\ConfigInstaller
* and \Drupal\Core\Config\TypedConfigManager.
*
* @return array
* An array mapping config object names with directories.
*/
protected function getAllFolders()
{
if (!isset($this->folders)) {
$this->folders = array();
$this->folders += $this->getCoreNames();
$install_profile = Settings::get('install_profile');
$profile = drupal_get_profile();
$extensions = $this->configStorage->read('core.extension');
// @todo Remove this scan as part of https://www.drupal.org/node/2186491
$listing = new ExtensionDiscovery(\Drupal::root());
if (!empty($extensions['module'])) {
$modules = $extensions['module'];
// Remove the install profile as this is handled later.
unset($modules[$install_profile]);
$profile_list = $listing->scan('profile');
if ($profile && isset($profile_list[$profile])) {
// Prime the drupal_get_filename() static cache with the profile info
// file location so we can use drupal_get_path() on the active profile
// during the module scan.
// @todo Remove as part of https://www.drupal.org/node/2186491
drupal_get_filename('profile', $profile, $profile_list[$profile]->getPathname());
}
$module_list_scan = $listing->scan('module');
$module_list = array();
foreach (array_keys($modules) as $module) {
if (isset($module_list_scan[$module])) {
$module_list[$module] = $module_list_scan[$module];
}
}
$this->folders += $this->getComponentNames($module_list);
}
if (!empty($extensions['theme'])) {
$theme_list_scan = $listing->scan('theme');
foreach (array_keys($extensions['theme']) as $theme) {
if (isset($theme_list_scan[$theme])) {
$theme_list[$theme] = $theme_list_scan[$theme];
}
}
$this->folders += $this->getComponentNames($theme_list);
}
if ($this->includeProfile) {
// The install profile can override module default configuration. We do
// this by replacing the config file path from the module/theme with the
// install profile version if there are any duplicates.
if (isset($profile)) {
if (!isset($profile_list)) {
$profile_list = $listing->scan('profile');
}
if (isset($profile_list[$profile])) {
$profile_folders = $this->getComponentNames(array($profile_list[$profile]));
$this->folders = $profile_folders + $this->folders;
}
}
}
}
return $this->folders;
}
示例3: testInstalled
/**
* Confirms that the installation succeeded.
*/
public function testInstalled()
{
$this->assertUrl('user/1');
$this->assertResponse(200);
// Confirm that we are logged-in after installation.
$this->assertText($this->rootUser->getUsername());
// Confirm that the minimal profile was installed.
$this->assertEqual(drupal_get_profile(), 'minimal');
}
示例4: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state)
{
// Make sure the install API is available.
include_once DRUPAL_ROOT . '/core/includes/install.inc';
// Get a list of all available modules.
$modules = system_rebuild_module_data();
$uninstallable = array_filter($modules, function ($module) use($modules) {
return empty($modules[$module->getName()]->info['required']) && $module->status;
});
// Include system.admin.inc so we can use the sort callbacks.
$this->moduleHandler->loadInclude('system', 'inc', 'system.admin');
$form['filters'] = array('#type' => 'container', '#attributes' => array('class' => array('table-filter', 'js-show')));
$form['filters']['text'] = array('#type' => 'search', '#title' => $this->t('Filter modules'), '#title_display' => 'invisible', '#size' => 30, '#placeholder' => $this->t('Filter by name or description'), '#description' => $this->t('Enter a part of the module name or description'), '#attributes' => array('class' => array('table-filter-text'), 'data-table' => '#system-modules-uninstall', 'autocomplete' => 'off'));
$form['modules'] = array();
// Only build the rest of the form if there are any modules available to
// uninstall;
if (empty($uninstallable)) {
return $form;
}
$profile = drupal_get_profile();
// Sort all modules by their name.
uasort($uninstallable, 'system_sort_modules_by_info_name');
$validation_reasons = $this->moduleInstaller->validateUninstall(array_keys($uninstallable));
$form['uninstall'] = array('#tree' => TRUE);
foreach ($uninstallable as $module_key => $module) {
$name = $module->info['name'] ?: $module->getName();
$form['modules'][$module->getName()]['#module_name'] = $name;
$form['modules'][$module->getName()]['name']['#markup'] = $name;
$form['modules'][$module->getName()]['description']['#markup'] = $this->t($module->info['description']);
$form['uninstall'][$module->getName()] = array('#type' => 'checkbox', '#title' => $this->t('Uninstall @module module', array('@module' => $name)), '#title_display' => 'invisible');
// If a validator returns reasons not to uninstall a module,
// list the reasons and disable the check box.
if (isset($validation_reasons[$module_key])) {
$form['modules'][$module->getName()]['#validation_reasons'] = $validation_reasons[$module_key];
$form['uninstall'][$module->getName()]['#disabled'] = TRUE;
}
// All modules which depend on this one must be uninstalled first, before
// we can allow this module to be uninstalled. (The installation profile
// is excluded from this list.)
foreach (array_keys($module->required_by) as $dependent) {
if ($dependent != $profile && drupal_get_installed_schema_version($dependent) != SCHEMA_UNINSTALLED) {
$name = isset($modules[$dependent]->info['name']) ? $modules[$dependent]->info['name'] : $dependent;
$form['modules'][$module->getName()]['#required_by'][] = $name;
$form['uninstall'][$module->getName()]['#disabled'] = TRUE;
}
}
}
$form['#attached']['library'][] = 'system/drupal.system.modules';
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Uninstall'));
return $form;
}
示例5: superfish_library_path
/**
* A helper function to generate a list of paths to the Superfish library files.
*/
public function superfish_library_path()
{
// Ensure the Libraries API module is installed and working.
if (function_exists('libraries_get_path')) {
$directory = libraries_get_path('superfish');
} elseif (file_exists('profiles/' . drupal_get_profile() . '/libraries/superfish')) {
$directory = 'profiles/' . drupal_get_profile() . '/libraries/superfish';
} else {
$directory = 'sites/all/libraries/superfish';
}
if (file_exists($directory)) {
$output = $directory . "/jquery.hoverIntent.minified.js\r\n" . $directory . "/superfish.js\r\n" . $directory . "/supersubs.js\r\n" . $directory . "/supposition.js\r\n" . $directory . "/sfsmallscreen.js\r\n" . $directory . "/sftouchscreen.js";
} else {
$output = '';
}
return $output;
}
示例6: collect
/**
* {@inheritdoc}
*/
public function collect(Request $request, Response $response, \Exception $exception = NULL)
{
$this->data['version'] = Drupal::VERSION;
$this->data['profile'] = drupal_get_profile();
$this->data['config_url'] = (new Drupal\Core\Url('webprofiler.settings', [], ['query' => $this->redirectDestination->getAsArray()]))->toString();
try {
$process = new Process("git log -1 --pretty=format:'%H - %s (%ci)' --abbrev-commit");
$process->setTimeout(3600);
$process->mustRun();
$this->data['git_commit'] = $process->getOutput();
$process = new Process("git log -1 --pretty=format:'%h' --abbrev-commit");
$process->setTimeout(3600);
$process->mustRun();
$this->data['abbr_git_commit'] = $process->getOutput();
} catch (ProcessFailedException $e) {
$this->data['git_commit'] = $this->data['git_commit_abbr'] = NULL;
}
}
示例7: setSearchDirs
/**
* Defines a list of the locations, where icon sets are searched.
*
* @return array
*/
protected function setSearchDirs()
{
// Similar to 'modules' and 'themes' directories inside an installation
// profile, installation profiles may want to place libraries into a
// 'libraries' directory.
$profile = drupal_get_profile();
if ($profile && strpos($profile, "core") === FALSE) {
$profile_path = drupal_get_path('profile', $profile);
$searchdirs[] = "{$profile_path}/libraries";
}
// Search sites/all/libraries for backwars-compatibility.
$searchdirs[] = 'sites/all/libraries';
// Always search the root 'libraries' directory.
$searchdirs[] = 'libraries';
// Also search sites/<domain>/*.
$site_path = \Drupal::service('kernel')->getSitePath();
$searchdirs[] = "{$site_path}/libraries";
// Add the social_media_links module directory.
$searchdirs[] = drupal_get_path('module', 'social_media_links') . '/libraries';
$this->searchDirs = $searchdirs;
}
示例8: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, $bundle_name = NULL)
{
$this->currentBundle = $this->assigner->loadBundle($bundle_name);
$settings = $this->currentBundle->getAssignmentSettings(self::METHOD_ID);
$this->setConfigTypeSelect($form, $settings['types']['config'], $this->t('exclude'));
$module_settings = $settings['module'];
$curated_settings = $settings['curated'];
$form['curated'] = array('#type' => 'checkbox', '#title' => $this->t('Exclude designated site-specific configuration'), '#default_value' => $curated_settings, '#description' => $this->t('Select this option to exclude from packaging items on a curated list of site-specific configuration.'));
$form['module'] = array('#type' => 'container', '#tree' => TRUE);
$form['module']['installed'] = array('#type' => 'checkbox', '#title' => $this->t('Exclude installed module-provided entity configuration'), '#default_value' => $module_settings['installed'], '#description' => $this->t('Select this option to exclude from packaging any configuration that is provided by already installed modules.'), '#attributes' => array('data-module-installed' => 'status'));
$show_if_module_installed_checked = array('visible' => array(':input[data-module-installed="status"]' => array('checked' => TRUE)));
$info = system_get_info('module', drupal_get_profile());
$form['module']['profile'] = array('#type' => 'checkbox', '#title' => $this->t("Don't exclude install profile's configuration"), '#default_value' => $module_settings['profile'], '#description' => $this->t("Select this option to not exclude from packaging any configuration that is provided by this site's install profile, %profile.", array('%profile' => $info['name'])), '#states' => $show_if_module_installed_checked);
$machine_name = $this->currentBundle->getMachineName();
$machine_name = !empty($machine_name) ? $machine_name : t('none');
$form['module']['namespace'] = array('#type' => 'checkbox', '#title' => $this->t("Don't exclude non-installed configuration by namespace"), '#default_value' => $module_settings['namespace'], '#description' => $this->t("Select this option to not exclude from packaging any configuration that is provided by non-installed modules with the package namespace (currently %namespace).", array('%namespace' => $machine_name)), '#states' => $show_if_module_installed_checked, '#attributes' => array('data-namespace' => 'status'));
$show_if_namespace_checked = array('visible' => array(':input[data-namespace="status"]' => array('checked' => TRUE), ':input[data-module-installed="status"]' => array('checked' => TRUE)));
$form['module']['namespace_any'] = array('#type' => 'checkbox', '#title' => $this->t("Don't exclude ANY configuration by namespace"), '#default_value' => $module_settings['namespace_any'], '#description' => $this->t("Select this option to not exclude from packaging any configuration that is provided by ANY modules with the package namespace (currently %namespace).\n Warning: Can cause installed configuration to be reassigned to different packages.", array('%namespace' => $machine_name)), '#states' => $show_if_namespace_checked);
$this->setActions($form);
return $form;
}
示例9: getAllFolders
/**
* Returns a map of all config object names and their folders.
*
* The list is based on enabled modules and themes. The active configuration
* storage is used rather than \Drupal\Core\Extension\ModuleHandler and
* \Drupal\Core\Extension\ThemeHandler in order to resolve circular
* dependencies between these services and \Drupal\Core\Config\ConfigInstaller
* and \Drupal\Core\Config\TypedConfigManager.
*
* @return array
* An array mapping config object names with directories.
*/
protected function getAllFolders()
{
if (!isset($this->folders)) {
$this->folders = array();
$this->folders += $this->getComponentNames('core', array('core'));
$extensions = $this->configStorage->read('core.extension');
if (!empty($extensions['module'])) {
$this->folders += $this->getComponentNames('module', array_keys($extensions['module']));
}
if (!empty($extensions['theme'])) {
$this->folders += $this->getComponentNames('theme', array_keys($extensions['theme']));
}
// The install profile can override module default configuration. We do
// this by replacing the config file path from the module/theme with the
// install profile version if there are any duplicates.
$profile_folders = $this->getComponentNames('profile', array(drupal_get_profile()));
$folders_to_replace = array_intersect_key($profile_folders, $this->folders);
if (!empty($folders_to_replace)) {
$this->folders = array_merge($this->folders, $folders_to_replace);
}
}
return $this->folders;
}
示例10: setUp
/**
* Generates a random database prefix, runs the install scripts on the
* prefixed database and enable the specified modules. After installation
* many caches are flushed and the internal browser is setup so that the
* page requests will run on the new prefix. A temporary files directory
* is created with the same name as the database prefix.
*
* @param ...
* List of modules to enable for the duration of the test.
*/
protected function setUp()
{
global $db_prefix, $user, $language;
// Store necessary current values before switching to prefixed database.
$this->originalLanguage = $language;
$this->originalLanguageDefault = variable_get('language_default');
$this->originalPrefix = $db_prefix;
$this->originalFileDirectory = file_directory_path();
$this->originalProfile = drupal_get_profile();
$clean_url_original = variable_get('clean_url', 0);
// Generate temporary prefixed database to ensure that tests have a clean starting point.
$db_prefix_new = Database::getConnection()->prefixTables('{simpletest' . mt_rand(1000, 1000000) . '}');
db_update('simpletest_test_id')->fields(array('last_prefix' => $db_prefix_new))->condition('test_id', $this->testId)->execute();
$db_prefix = $db_prefix_new;
// Create test directory ahead of installation so fatal errors and debug
// information can be logged during installation process.
// Use temporary files directory with the same prefix as the database.
$public_files_directory = $this->originalFileDirectory . '/simpletest/' . substr($db_prefix, 10);
$private_files_directory = $public_files_directory . '/private';
$temp_files_directory = $private_files_directory . '/temp';
// Create the directories
file_prepare_directory($public_files_directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
file_prepare_directory($private_files_directory, FILE_CREATE_DIRECTORY);
file_prepare_directory($temp_files_directory, FILE_CREATE_DIRECTORY);
$this->generatedTestFiles = FALSE;
// Log fatal errors.
ini_set('log_errors', 1);
ini_set('error_log', $public_files_directory . '/error.log');
// Reset all statics so that test is performed with a clean environment.
drupal_static_reset();
include_once DRUPAL_ROOT . '/includes/install.inc';
drupal_install_system();
$this->preloadRegistry();
// Include the default profile
variable_set('install_profile', 'standard');
$profile_details = install_profile_info('standard', 'en');
// Install the modules specified by the default profile.
drupal_install_modules($profile_details['dependencies'], TRUE);
drupal_static_reset('_node_types_build');
if ($modules = func_get_args()) {
// Install modules needed for this test.
drupal_install_modules($modules, TRUE);
}
// Because the schema is static cached, we need to flush
// it between each run. If we don't, then it will contain
// stale data for the previous run's database prefix and all
// calls to it will fail.
drupal_get_schema(NULL, TRUE);
// Run default profile tasks.
$install_state = array();
drupal_install_modules(array('standard'), TRUE);
// Rebuild caches.
node_types_rebuild();
actions_synchronize();
_drupal_flush_css_js();
$this->refreshVariables();
$this->checkPermissions(array(), TRUE);
// Log in with a clean $user.
$this->originalUser = $user;
drupal_save_session(FALSE);
$user = user_load(1);
// Restore necessary variables.
variable_set('install_task', 'done');
variable_set('clean_url', $clean_url_original);
variable_set('site_mail', 'simpletest@example.com');
// Set up English language.
unset($GLOBALS['conf']['language_default']);
$language = language_default();
// Set path variables
variable_set('file_public_path', $public_files_directory);
variable_set('file_private_path', $private_files_directory);
variable_set('file_temporary_path', $temp_files_directory);
// Use the test mail class instead of the default mail handler class.
variable_set('mail_system', array('default-system' => 'TestingMailSystem'));
drupal_set_time_limit($this->timeLimit);
}
示例11: prepareEnvironment
/**
* Prepares the current environment for running the test.
*
* Backups various current environment variables and resets them, so they do
* not interfere with the Drupal site installation in which tests are executed
* and can be restored in TestBase::restoreEnvironment().
*
* Also sets up new resources for the testing environment, such as the public
* filesystem and configuration directories.
*
* This method is private as it must only be called once by TestBase::run()
* (multiple invocations for the same test would have unpredictable
* consequences) and it must not be callable or overridable by test classes.
*
* @see TestBase::beforePrepareEnvironment()
*/
private function prepareEnvironment()
{
$user = \Drupal::currentUser();
// Allow (base) test classes to backup global state information.
$this->beforePrepareEnvironment();
// Create the database prefix for this test.
$this->prepareDatabasePrefix();
$language_interface = \Drupal::languageManager()->getCurrentLanguage();
// When running the test runner within a test, back up the original database
// prefix.
if (DRUPAL_TEST_IN_CHILD_SITE) {
$this->originalPrefix = drupal_valid_test_ua();
}
// Backup current in-memory configuration.
$site_path = \Drupal::service('site.path');
$this->originalSite = $site_path;
$this->originalSettings = Settings::getAll();
$this->originalConfig = $GLOBALS['config'];
// @todo Remove all remnants of $GLOBALS['conf'].
// @see https://www.drupal.org/node/2183323
$this->originalConf = isset($GLOBALS['conf']) ? $GLOBALS['conf'] : NULL;
// Backup statics and globals.
$this->originalContainer = clone \Drupal::getContainer();
$this->originalLanguage = $language_interface;
$this->originalConfigDirectories = $GLOBALS['config_directories'];
// Save further contextual information.
// Use the original files directory to avoid nesting it within an existing
// simpletest directory if a test is executed within a test.
$this->originalFileDirectory = Settings::get('file_public_path', $site_path . '/files');
$this->originalProfile = drupal_get_profile();
$this->originalUser = isset($user) ? clone $user : NULL;
// Prevent that session data is leaked into the UI test runner by closing
// the session and then setting the session-name (i.e. the name of the
// session cookie) to a random value. If a test starts a new session, then
// it will be associated with a different session-name. After the test-run
// it can be safely destroyed.
// @see TestBase::restoreEnvironment()
if (PHP_SAPI !== 'cli' && session_status() === PHP_SESSION_ACTIVE) {
session_write_close();
}
$this->originalSessionName = session_name();
session_name('SIMPLETEST' . Crypt::randomBytesBase64());
// Save and clean the shutdown callbacks array because it is static cached
// and will be changed by the test run. Otherwise it will contain callbacks
// from both environments and the testing environment will try to call the
// handlers defined by the original one.
$callbacks =& drupal_register_shutdown_function();
$this->originalShutdownCallbacks = $callbacks;
$callbacks = array();
// Create test directory ahead of installation so fatal errors and debug
// information can be logged during installation process.
file_prepare_directory($this->siteDirectory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
// Prepare filesystem directory paths.
$this->publicFilesDirectory = $this->siteDirectory . '/files';
$this->privateFilesDirectory = $this->siteDirectory . '/private';
$this->tempFilesDirectory = $this->siteDirectory . '/temp';
$this->translationFilesDirectory = $this->siteDirectory . '/translations';
$this->generatedTestFiles = FALSE;
// Ensure the configImporter is refreshed for each test.
$this->configImporter = NULL;
// Unregister all custom stream wrappers of the parent site.
// Availability of Drupal stream wrappers varies by test base class:
// - KernelTestBase supports and maintains stream wrappers in a custom
// way.
// - WebTestBase re-initializes Drupal stream wrappers after installation.
// The original stream wrappers are restored after the test run.
// @see TestBase::restoreEnvironment()
$this->originalContainer->get('stream_wrapper_manager')->unregister();
// Reset statics.
drupal_static_reset();
// Ensure there is no service container.
$this->container = NULL;
\Drupal::unsetContainer();
// Unset globals.
unset($GLOBALS['config_directories']);
unset($GLOBALS['config']);
unset($GLOBALS['conf']);
// Log fatal errors.
ini_set('log_errors', 1);
ini_set('error_log', DRUPAL_ROOT . '/' . $this->siteDirectory . '/error.log');
// Change the database prefix.
$this->changeDatabasePrefix();
// After preparing the environment and changing the database prefix, we are
// in a valid test environment.
//.........这里部分代码省略.........
示例12: getFormOptions
/**
* Return driver specific configuration options.
*
* @param $database
* An array of driver specific configuration options.
*
* @return
* The options form array.
*/
public function getFormOptions(array $database)
{
$form['database'] = array('#type' => 'textfield', '#title' => t('Database name'), '#default_value' => empty($database['database']) ? '' : $database['database'], '#size' => 45, '#required' => TRUE, '#states' => array('required' => array(':input[name=driver]' => array('value' => $this->pdoDriver))));
$form['username'] = array('#type' => 'textfield', '#title' => t('Database username'), '#default_value' => empty($database['username']) ? '' : $database['username'], '#size' => 45, '#required' => TRUE, '#states' => array('required' => array(':input[name=driver]' => array('value' => $this->pdoDriver))));
$form['password'] = array('#type' => 'password', '#title' => t('Database password'), '#default_value' => empty($database['password']) ? '' : $database['password'], '#required' => FALSE, '#size' => 45);
$form['advanced_options'] = array('#type' => 'details', '#title' => t('Advanced options'), '#weight' => 10);
$profile = drupal_get_profile();
$db_prefix = $profile == 'standard' ? 'drupal_' : $profile . '_';
$form['advanced_options']['prefix'] = array('#type' => 'textfield', '#title' => t('Table name prefix'), '#default_value' => empty($database['prefix']) ? '' : $database['prefix'], '#size' => 45, '#description' => t('If more than one application will be sharing this database, a unique table name prefix–such as %prefix–will prevent collisions.', array('%prefix' => $db_prefix)), '#weight' => 10);
$form['advanced_options']['host'] = array('#type' => 'textfield', '#title' => t('Host'), '#default_value' => empty($database['host']) ? 'localhost' : $database['host'], '#size' => 45, '#maxlength' => 255, '#required' => TRUE);
$form['advanced_options']['port'] = array('#type' => 'number', '#title' => t('Port number'), '#default_value' => empty($database['port']) ? '' : $database['port'], '#min' => 0, '#max' => 65535);
return $form;
}
示例13: getProfileName
/**
* {@inheritdoc}
*/
public function getProfileName()
{
$name = $this->isProfile() ? $this->profileName : '';
return !empty($name) ? $name : drupal_get_profile();
}
示例14: setUp
/**
* Generates a random database prefix, runs the install scripts on the
* prefixed database and enable the specified modules. After installation
* many caches are flushed and the internal browser is setup so that the
* page requests will run on the new prefix. A temporary files directory
* is created with the same name as the database prefix.
*
* @param ...
* List of modules to enable for the duration of the test. This can be
* either a single array or a variable number of string arguments.
*/
protected function setUp()
{
global $user, $language, $conf;
// Generate a temporary prefixed database to ensure that tests have a clean starting point.
$this->databasePrefix = 'simpletest' . mt_rand(1000, 1000000);
db_update('simpletest_test_id')->fields(array('last_prefix' => $this->databasePrefix))->condition('test_id', $this->testId)->execute();
// Clone the current connection and replace the current prefix.
$connection_info = Database::getConnectionInfo('default');
Database::renameConnection('default', 'simpletest_original_default');
foreach ($connection_info as $target => $value) {
$connection_info[$target]['prefix'] = array('default' => $value['prefix']['default'] . $this->databasePrefix);
}
Database::addConnectionInfo('default', 'default', $connection_info['default']);
// Store necessary current values before switching to prefixed database.
$this->originalLanguage = $language;
$this->originalLanguageDefault = variable_get('language_default');
$this->originalFileDirectory = variable_get('file_public_path', conf_path() . '/files');
$this->originalProfile = drupal_get_profile();
$this->removeTables = variable_get('simpletest_remove_tables', TRUE);
$clean_url_original = variable_get('clean_url', 0);
// Save and clean shutdown callbacks array because it static cached and
// will be changed by the test run. If we don't, then it will contain
// callbacks from both environments. So testing environment will try
// to call handlers from original environment.
$callbacks =& drupal_register_shutdown_function();
$this->originalShutdownCallbacks = $callbacks;
$callbacks = array();
// Create test directory ahead of installation so fatal errors and debug
// information can be logged during installation process.
// Use temporary files directory with the same prefix as the database.
$public_files_directory = $this->originalFileDirectory . '/simpletest/' . substr($this->databasePrefix, 10);
$private_files_directory = $public_files_directory . '/private';
$temp_files_directory = $private_files_directory . '/temp';
// Create the directories
file_prepare_directory($public_files_directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
file_prepare_directory($private_files_directory, FILE_CREATE_DIRECTORY);
file_prepare_directory($temp_files_directory, FILE_CREATE_DIRECTORY);
$this->generatedTestFiles = FALSE;
// Log fatal errors.
ini_set('log_errors', 1);
ini_set('error_log', $public_files_directory . '/error.log');
// Reset all statics and variables to perform tests in a clean environment.
$conf = array();
drupal_static_reset();
// Set the test information for use in other parts of Drupal.
$test_info =& $GLOBALS['drupal_test_info'];
$test_info['test_run_id'] = $this->databasePrefix;
$test_info['in_child_site'] = FALSE;
$this->setUpInstall(func_get_args(), $public_files_directory, $private_files_directory, $temp_files_directory);
// Rebuild caches.
drupal_static_reset();
drupal_flush_all_caches();
// Register actions declared by any modules.
actions_synchronize();
// Reload global $conf array and permissions.
$this->refreshVariables();
$this->checkPermissions(array(), TRUE);
// Reset statically cached schema for new database prefix.
drupal_get_schema(NULL, TRUE);
// Run cron once in that environment, as install.php does at the end of
// the installation process.
drupal_cron_run();
// Log in with a clean $user.
$this->originalUser = $user;
drupal_save_session(FALSE);
$user = user_load(1);
$this->setUpVariables($clean_url_original);
// Set up English language.
unset($GLOBALS['conf']['language_default']);
$language = language_default();
// Use the test mail class instead of the default mail handler class.
variable_set('mail_system', array('default-system' => 'TestingMailSystem'));
drupal_set_time_limit($this->timeLimit);
}
示例15: setUp
/**
* Generates a random database prefix, runs the install scripts on the
* prefixed database and enable the specified modules. After installation
* many caches are flushed and the internal browser is setup so that the
* page requests will run on the new prefix. A temporary files directory
* is created with the same name as the database prefix.
*
* @param ...
* List of modules to enable for the duration of the test. This can be
* either a single array or a variable number of string arguments.
*/
protected function setUp()
{
global $user, $language, $conf;
// Generate a temporary prefixed database to ensure that tests have a clean starting point.
$this->databasePrefix = 'simpletest' . mt_rand(1000, 1000000);
db_update('simpletest_test_id')->fields(array('last_prefix' => $this->databasePrefix))->condition('test_id', $this->testId)->execute();
// Clone the current connection and replace the current prefix.
$connection_info = Database::getConnectionInfo('default');
Database::renameConnection('default', 'simpletest_original_default');
foreach ($connection_info as $target => $value) {
$connection_info[$target]['prefix'] = array('default' => $value['prefix']['default'] . $this->databasePrefix);
}
Database::addConnectionInfo('default', 'default', $connection_info['default']);
// Store necessary current values before switching to prefixed database.
$this->originalLanguage = $language;
$this->originalLanguageDefault = variable_get('language_default');
$this->originalFileDirectory = variable_get('file_public_path', conf_path() . '/files');
$this->originalProfile = drupal_get_profile();
$clean_url_original = variable_get('clean_url', 0);
// Set to English to prevent exceptions from utf8_truncate() from t()
// during install if the current language is not 'en'.
// The following array/object conversion is copied from language_default().
$language = (object) array('language' => 'en', 'name' => 'English', 'native' => 'English', 'direction' => 0, 'enabled' => 1, 'plurals' => 0, 'formula' => '', 'domain' => '', 'prefix' => '', 'weight' => 0, 'javascript' => '');
// Save and clean shutdown callbacks array because it static cached and
// will be changed by the test run. If we don't, then it will contain
// callbacks from both environments. So testing environment will try
// to call handlers from original environment.
$callbacks =& drupal_register_shutdown_function();
$this->originalShutdownCallbacks = $callbacks;
$callbacks = array();
// Create test directory ahead of installation so fatal errors and debug
// information can be logged during installation process.
// Use temporary files directory with the same prefix as the database.
$public_files_directory = $this->originalFileDirectory . '/simpletest/' . substr($this->databasePrefix, 10);
$private_files_directory = $public_files_directory . '/private';
$temp_files_directory = $private_files_directory . '/temp';
// Create the directories
file_prepare_directory($public_files_directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
file_prepare_directory($private_files_directory, FILE_CREATE_DIRECTORY);
file_prepare_directory($temp_files_directory, FILE_CREATE_DIRECTORY);
$this->generatedTestFiles = FALSE;
// Log fatal errors.
ini_set('log_errors', 1);
ini_set('error_log', $public_files_directory . '/error.log');
// Reset all statics and variables to perform tests in a clean environment.
$conf = array();
drupal_static_reset();
// Set the test information for use in other parts of Drupal.
$test_info =& $GLOBALS['drupal_test_info'];
$test_info['test_run_id'] = $this->databasePrefix;
$test_info['in_child_site'] = FALSE;
include_once DRUPAL_ROOT . '/includes/install.inc';
drupal_install_system();
$this->preloadRegistry();
// Set path variables.
variable_set('file_public_path', $public_files_directory);
variable_set('file_private_path', $private_files_directory);
variable_set('file_temporary_path', $temp_files_directory);
// Include the testing profile.
variable_set('install_profile', $this->profile);
$profile_details = install_profile_info($this->profile, 'en');
// Install the modules specified by the testing profile.
module_enable($profile_details['dependencies'], FALSE);
// Install modules needed for this test. This could have been passed in as
// either a single array argument or a variable number of string arguments.
// @todo Remove this compatibility layer in Drupal 8, and only accept
// $modules as a single array argument.
$modules = func_get_args();
if (isset($modules[0]) && is_array($modules[0])) {
$modules = $modules[0];
}
if ($modules) {
$success = module_enable($modules, TRUE);
$this->assertTrue($success, t('Enabled modules: %modules', array('%modules' => implode(', ', $modules))));
}
// Run the profile tasks.
$install_profile_module_exists = db_query("SELECT 1 FROM {system} WHERE type = 'module' AND name = :name", array(':name' => $this->profile))->fetchField();
if ($install_profile_module_exists) {
module_enable(array($this->profile), FALSE);
}
// Reset/rebuild all data structures after enabling the modules.
$this->resetAll();
// Run cron once in that environment, as install.php does at the end of
// the installation process.
drupal_cron_run();
// Log in with a clean $user.
$this->originalUser = $user;
drupal_save_session(FALSE);
$user = user_load(1);
//.........这里部分代码省略.........