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_*()
Related
I am trying to automate the process of enabling/disabling the module for my Drupal-8 website. As far I could understand from the docs, Drupal saves the info related to the modules in the table config inside its database (drupal/sites/default/files/.ht.sqlite).
Before enabling the module snowflake, I'm not unable to see any entry for it, but after manually enabling it through http://website/admin/modules, I can see this entry at the end of the table.
collection name data
---------- -------------- --------------------------------------------------------------------------------------------------------------------
snowflakes.set a:5:{s:8:"langcode";s:2:"en";s:7:"enabled";b:1;s:13:"exclude_admin";b:1;s:13:"toggle_button";b:0;s:5:"_core";a:1:{s:19:"default_config_hash";s:43:"gWu2_RT_6nrFtvXiYNQFgZm17c3CEXCxrb-JnsCFKmM";}}
Is there any file/function that is generating entries like this for similar modules? Once I'm able to figure this out, it might help me automate the process of enabling a module without manually clicking the checkbox from http://website/admin/modules every time.
you can use drush to enable/disable modules.
See https://www.drush.org/latest/
Example (install):
drush pm:install "mymodule"
Unninstall
drush pm:uninstall "mymodule"
replace "mymodule" with the module machine name.
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.
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.
The plugin I'm unit testing with phpunit has a dependency on another plugin, using is_plugin_active().
When testing the dependency in my unit test that function always returns false/inactive, when the it is definitely active, because it's working properly in the plugin itself. It seems to be accessible, so there must be some logic error when it comes to this wordpress core function.
This is my code:
function test_requirementsMet_true() {
$this->assertTrue(is_plugin_active('pluginFolder/plugin.php'));
}
Does anyone know of a work-around?
Assuming you scaffolded your tests with WP-CLI, you should know the plugin is loaded as an mu-plugin rather than a vanilla plugin, which means:
Only plugins installed in the plugins/ folder can be active.
Plugins in the mu-plugins/ folder can’t be "activated," so this
function will return false for those plugins.
I'm building a site starting from the magnolia empty webapp with maven.
All is ok but now I'm now writing the contact page of the site. I'd like to use the magnolia mail module for this. So I installed the mail module and the form module.
Problem:
After installing the form module in magnolia 5.4, the template called "Form" does not appear in the template selection when creating a new page in the pages app.
As it seems from the Documentation, it should be there.
Details:
Other templates, created by me with yaml and freemarker, correctly appear (and i can use them correctly).
The mail module is up and running and configured: i can send a mail to myself with the "verify setting" page, using a template i made, but i'd like to create a contact module for my site.
I installed the module with maven like:
dependency: groupId:info.magnolia, artifactId:magnolia-module-form , version:2.3
and installed it with the usual steps (installed module, wait , correctly completed without messages, started magnolia)
I DO NOT have STK installed since i'm using MTE... and i've other modules installed (resources, site, mail, MTE, DAM, etc...)
Am I missing something or doing something wrong? :|
Otherwise, Can the magnolia mail module simply be used standalone without the form module to send out a email, may be pointing a hand-written form to somewhere?
Or, best option imho: can I make a new form template with yaml? I can't find docs about it.
Thank you!.
Edit: I tried to install the STK along with MTE (I correctly updated to magnolia 5.4.1) but it relies on data-module 2.3.6 (which i don't have in my dependencies and which i don't use) so it won't install the STK. Also , installing STK just for a form template seems overkill to me. I'd prefere to understand how to insert a form in one of my templates.
Preinstalled templates are for STK. If you want to use Magnolia without STK, then you need to write template yourself, but in exchange have much more freedom in what you can do with that template. Once you create and register template you should be able to use it.
Re STK - latest version doesn't have any dependency on data module - see module descriptor. Either I'm blind or there is no such dependency. :D
HTH,
Jan