In Drupal 8 is there a way to automatically set the installation language for a new installation? I'll be basing it on the URL, I already have the logic to work out which language should be selected but unsure how to make it the default selection when doing a fresh install of Drupal.
To start, you can populate the install state parameters via some URL queries. Adding ?langcode=en would default it to English.
Otherwise, you would have to use a custom profile to ensure a proper default selection is made. The related code is in core/includes/install.core.inc. The install_drupal function is what performs Drupal's install. The langcode is determined in install_begin_request via the install state which is populated by install_state_defaults.
You'd need to get the langcode populated
if (!empty($install_state['parameters']['langcode'])) {
$install_state['parameters']['langcode'] = preg_replace('/[^a-zA-Z_0-9\-]/', '', $install_state['parameters']['langcode']);
}
Looking through the code, this is only possible via query parameters
// Add any installation parameters passed in via the URL.
if ($install_state['interactive']) {
$install_state['parameters'] += $request->query->all();
}
Unless you had a custom install profile that invoked hook_install_tasks to add a task at the beginning of the install process to set the default language code.
Related
I have been given the task of moving two Drupal-based websites to a new server, not because I'm a Drupal expert but I'm the only one in the office with PHP programming skills. One is a Drupal 7 site, the other Drupal 8. These were both given to me as DevDesktop archives and SQL dumps. The Drupal 7 site was pretty straightforward - copied the contents of the docroot up to the new server, created and populated a new MySQL database and edited the default site settings file to point at the new dbase. So the Drupal 7 site works fine. Doing the same with the Drupal 8 site the main problem seems to be it won't load any CSS or Javascript.
In the Javascript Console it threw me off the scent slightly because it said the mime type of the CSS was incorrect, but on further inspection that's because the path to the CSS was returning a 404.
Compounding the problem is Antibot, and as Javascript isn't loading, although I have the username and password for the admin user, I can't login because Antibot keeps sending me back to the homepage telling me to enable Javascript. I have edited settings.php to enable /core/rebuild.php and tried that, but doesn't appear to make any difference. I've also manually truncated the 'cache_...' tables and that doesn't seem to work either. Note that I DON'T have access to SSH on the new server, so can't use drush.
Refused to apply style from '[]' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
Failed to load resource: the server responded with a status of 404 (Not Found)
What it does look like to my non-expert eye is that Drupal is configured somehow to server up optimised versions of the CSS and JS from virtual directories /css/ and /js/, although those paths don't actually exist on the server. I checked the .htaccess file, but other than some clever stuff to deliver gzipped versions to gzip-capable browsers, couldn't see anything in there that would get the server to the correct file. Perhaps if someone could explain how Drupal routes a request to /css/ or /js/ to the right file, that would help my understanding further.
Ultimately I think this problem is because Drupal 8 wants to deliver optimised files, but the cache is screwed and Antibot won't let me get into admin to turn off aggregation.
I have full access to the server files and database, but not drush. Is there a way to turn off the CSS & JS aggregation apart from via the admin menus?
In this situation you can disable aggregation either :
by editing settings.php or settings.local.php :
/**
* Disable CSS and JS aggregation.
*/
$config['system.performance']['css']['preprocess'] = FALSE;
$config['system.performance']['js']['preprocess'] = FALSE;
or via sql, but you have to decode and unserialize blob data from the config table to make the changes, and then make the reverse process :
# Query :
SELECT name, CONVERT (`data` USING utf8) FROM config WHERE `name`='system.performance';
# Unserialize query output and edit data locally
$config = unserialize($output);
$data['css']['preprocess'] = FALSE;
$data['js']['preprocess'] = FALSE;
# Then serialize data and write it back into the config table
# (original encoding is probably `LONGBLOB` but it may differ depending on the backend).
Once you can ssh into the server, you will need to reset permissions and ownership under sites/default/files/ before enabling aggregation again :
mkdir -p sites/default/files/{css,js}
chown -R apache:apache sites/default/files/
chmod -R 0755 sites/default/files/
You may also want to check if the public file path setting (in settings.php) is properly set according to where these ressources are actually located :
$settings['file_public_path'] = 'sites/default/files';
I'm updating Fishpig Wordpress-Integration to version 4.5.1.5 (with addons ACF, CPT, CS, Root, Multisite) in a new ansible-deployment. Now I get the follwoing error in the Magento-Backend :
Permissions The following file must be writable: /path/to/magento/wp/wp-includes/l10n.php
Why at all should a magento-module have write-permissions on a wordpress-core-file?
We prefer strongly to have separate concerns, so that the wp-core-files can't be compromised by anything from magento-side.
The questions are:
for which task in Fishpig (or it's addons) this write permission will be used?
could the _validateL10nPermissions() be overwritten for not checking this file without loosing an important functionality in Fishpig?
Would be great to get some clarification about this point.
This file needs to be modified because both Magento and WordPress have a PHP function with the same name, specifically the translation function:
function __($args);
It is not possible to have multiple functions in PHP with the same name. The only way to include the WP code base into Magento and make it available is to stop either Magento or WordPress from defining this function. The module chooses to modify the WP file instead of the Magento file.
The modification it makes it a simple one. It simply wraps the function definition in WordPress with a call to function_exists. This checks whether the function has already been defined (ie. in Magento) and if it has, it doesn't define it again. If it hasn't been defined, it defines it.
if (!function_exists('__')) {
function __($args);
}
This allows WordPress to work on it's own and when included into the Magento code. Without this modification, it is not possible to use Magento and WordPress together.
Write permissions are only required if the file does not include the modification. If the file already includes the modification then write permissions are not required. If you don't want to give write permissions on your live server, have the file modification take place either on a dev/staging server or make the file modification yourself as part of your deployment process.
I'm building a small website with Symfony2 (i.e. not Symfony 1.x). I used the default CRUD generator from an entity created using the CLI generator. However, when it's saved to the database, it's being saved with escaping slashes.
Where is the right place to stop that happening? In the entity, the repostiory, the controller or the form? Is there some magical function for doing it?
Turned out to be nothing to do with Symfony. I'm using MAMP, and magic_quotes_gpc was turned on. For future reference, go to your php.ini file and set
magic_quotes_gpc = Off
To check whether magic quotes are turned on, run just do
if(get_magic_quotes_gpc()) { die('magic quotes turned on'); }
I am trying to get a Drupal to run a custom hooks; one that needs to run when a module is being installed and another for when the module is being unistalled. Is there a hook or a trigger that I can use to have Drupal run the hook while the module is installing or uninstalling? The hook that I need to run builds taxonomy terms from an array. I am basing the lay out on the hook_schema. An example of the implementation of this hook is:
function mymodule_install_taxonomy() {
return array(
<<Taxonomy Structure Here>>
);
}
This code would be placed in the .install file.
When your own module is installed or for others?
For your own, there is hook_install() (only called the first time your module is installed, usually used to install the schema defined in hook_schema() in Drupal 6, this is automated in Drupal 7), hook_uninstall(), hook_enable() (called every time your module is enabled) and finally hook_disable() (when your module is disabled).
Drupal 7 has also added a similar set of hooks that is however called when other modules are installed, uninstalled, enabled or disabled, see hook_modules_*()
I've just moved a Drupal to my localserver and I forgot to disable Secure Pages.
Now I cannot access admin pages, because the site switches to HTTPS.
How can I disable it?
In your settings.php file:
$conf['securepages_enable'] = FALSE;
This will override the database setting.
In your sites/example.com/settings.php, leave this line out, and then it will use whatever value is in the database.
If you are using drush, you can keep the Secure Pages module enabled and just turn off the checkbox in the module's own config like:
drush vset securepages_enable 0
This will stop the redirect.
you can also change the URLs if you want, as follows, but the above is usually enough.
drush vset securepages_basepath http://nominet.dev
drush vset securepages_basepath_ssl http://nominet.dev
I'm running Drupal 7 btw, so YMMV, but seems to be a simple drush based solution following on from the above answer.
The way I've done it without disabling the module is to use SQL to change the variable setting. First backup your database (in case you put a semicolon in the wrong place; scratch that, always back up your database before making changes on the command line) and then run the following SQL on your database:
UPDATE variable SET value = 's:1:"0";' WHERE name = 'securepages_enable';
Then:
DELETE FROM cache;
DELETE FROM cache_page;
You need those two lines in order to clear the cache, otherwise the variable might stick around for a while.
If you have Drush installed:
drush dis -y securepages
I know this question is old and has been answered a few times, but there's another option that hasn't been suggested yet.
You could disable it completely:
// Disable SecurePages completely.
$conf['securepages_enable'] = FALSE;
and alter settings.php to enforce HTTPS depending on some context, e.g.:
if (isset($_SERVER['environment'] && $_SERVER['environment'] == 'staging')) {
$conf['securepages_basepath'] = 'http://staging.example.com';
$conf['securepages_basepath_ssl'] = 'https://staging.example.com';
} else if (isset($_SERVER['environment'] && $_SERVER['environment'] == 'production')) {
$conf['securepages_basepath'] = 'http://www.example.com';
$conf['securepages_basepath_ssl'] = 'https://www.example.com';
} else {
// We're on dev or some other server instance where SSL isn't needed.
$conf['securepages_enable'] = FALSE;
}
This is just an example, but it's been a helpful way for us to manage sites that exist on a dev server, a QA server, and a production server, where we want to track settings.php changes in version control without having to change things in each environment.
You can disable the module directly via the database. Just go into the system table, look for your module under the name column, and set the status field to zero.