How can I update existing config from a custom module's config/install yamls?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{
margin-bottom:0;
}
I added some config yml files to my module's config/install directory so that it is installed directly when installing my module, it works well only if there isn't a config file with the same name installed already and only if it's the first install.
So my question is there a way to update the config files already installed with my module's config file, and delete them when uninstalling the module ?
8 installing configuration-management
add a comment
|
I added some config yml files to my module's config/install directory so that it is installed directly when installing my module, it works well only if there isn't a config file with the same name installed already and only if it's the first install.
So my question is there a way to update the config files already installed with my module's config file, and delete them when uninstalling the module ?
8 installing configuration-management
I wouldn't recommend reinventing the Features module. But let's say this is a contrib module and you updated the install yamls that won't fire on sites that had that module installed already, you need to additionally provide your entity changes viahook_update_N
programmatically.
– leymannx
May 28 at 11:11
Maybe you can provide more details and context.
– leymannx
May 28 at 11:12
add a comment
|
I added some config yml files to my module's config/install directory so that it is installed directly when installing my module, it works well only if there isn't a config file with the same name installed already and only if it's the first install.
So my question is there a way to update the config files already installed with my module's config file, and delete them when uninstalling the module ?
8 installing configuration-management
I added some config yml files to my module's config/install directory so that it is installed directly when installing my module, it works well only if there isn't a config file with the same name installed already and only if it's the first install.
So my question is there a way to update the config files already installed with my module's config file, and delete them when uninstalling the module ?
8 installing configuration-management
8 installing configuration-management
edited May 28 at 13:40
leymannx
8,7345 gold badges37 silver badges71 bronze badges
8,7345 gold badges37 silver badges71 bronze badges
asked May 28 at 10:09
YumiYumi
62 bronze badges
62 bronze badges
I wouldn't recommend reinventing the Features module. But let's say this is a contrib module and you updated the install yamls that won't fire on sites that had that module installed already, you need to additionally provide your entity changes viahook_update_N
programmatically.
– leymannx
May 28 at 11:11
Maybe you can provide more details and context.
– leymannx
May 28 at 11:12
add a comment
|
I wouldn't recommend reinventing the Features module. But let's say this is a contrib module and you updated the install yamls that won't fire on sites that had that module installed already, you need to additionally provide your entity changes viahook_update_N
programmatically.
– leymannx
May 28 at 11:11
Maybe you can provide more details and context.
– leymannx
May 28 at 11:12
I wouldn't recommend reinventing the Features module. But let's say this is a contrib module and you updated the install yamls that won't fire on sites that had that module installed already, you need to additionally provide your entity changes via
hook_update_N
programmatically.– leymannx
May 28 at 11:11
I wouldn't recommend reinventing the Features module. But let's say this is a contrib module and you updated the install yamls that won't fire on sites that had that module installed already, you need to additionally provide your entity changes via
hook_update_N
programmatically.– leymannx
May 28 at 11:11
Maybe you can provide more details and context.
– leymannx
May 28 at 11:12
Maybe you can provide more details and context.
– leymannx
May 28 at 11:12
add a comment
|
2 Answers
2
active
oldest
votes
A module install should not update config. If you want to update existing config, your module should implement hook_update_N()
(see docs) instead.
However, you could add a dependencies: enforced
section to your YML config files. This will remove your existing config on module uninstall, and install the newest config on module reinstall. This way you can "emulate" a simple update mechanism for your own, private custom module. See doc for enforced config dependencies
add a comment
|
You can update custom config with a settings form you build.
In a custom module custom_mailing add a file called custom_mailing.routing.yml add the following route:
custom_mailing.route_admin_settings:
path: '/admin/config/mailing'
defaults:
_title: 'Custom mailing'
_form: 'Drupalcustom_mailingFormAdminSettingsForm'
requirements:
_permission: 'administer custom_mailing settings'
Now I want a boolean value to be editable. I create a file in a map config/install
called custom_mailings.settings.yml with the following content:
mailsettings:
enabled: 0
In a module called custom_mailing. Inside src/Form
add file called AdminSettingsForm.php
.
<?php
namespace Drupalcustom_mailingForm;
use DrupalCoreFormConfigFormBase;
use DrupalCoreFormFormStateInterface;
/**
* Class AdminSettingsForm.
*
* @package Drupalcustom_mailingForm
*/
class AdminSettingsForm extends ConfigFormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'custom_mailing_admin_settings_form';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'custom_mailing.settings',
];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this->config('custom_mailing.settings');
$form['mailsettings'] = [
'#tree' => TRUE,
'#type' => 'fieldset',
'#title' => $this->t('Email settings'),
];
$form['mailsettings']['enabled'] = [
'#type' => 'checkbox',
'#title' => $this->t('Enable sending of e-mails.'),
'#default_value' => $config->get('mailsettings.enabled'),
];
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = $this->config('custom_mailing.settings');
$config->set('mailsettings', $form_state->getValue('mailsettings'));
$config->save();
parent::submitForm($form, $form_state);
}
}
Config will be deleted when disabling the module btw
– Stef Van Looveren
May 28 at 15:31
add a comment
|
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "220"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdrupal.stackexchange.com%2fquestions%2f281676%2fhow-can-i-update-existing-config-from-a-custom-modules-config-install-yamls%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
A module install should not update config. If you want to update existing config, your module should implement hook_update_N()
(see docs) instead.
However, you could add a dependencies: enforced
section to your YML config files. This will remove your existing config on module uninstall, and install the newest config on module reinstall. This way you can "emulate" a simple update mechanism for your own, private custom module. See doc for enforced config dependencies
add a comment
|
A module install should not update config. If you want to update existing config, your module should implement hook_update_N()
(see docs) instead.
However, you could add a dependencies: enforced
section to your YML config files. This will remove your existing config on module uninstall, and install the newest config on module reinstall. This way you can "emulate" a simple update mechanism for your own, private custom module. See doc for enforced config dependencies
add a comment
|
A module install should not update config. If you want to update existing config, your module should implement hook_update_N()
(see docs) instead.
However, you could add a dependencies: enforced
section to your YML config files. This will remove your existing config on module uninstall, and install the newest config on module reinstall. This way you can "emulate" a simple update mechanism for your own, private custom module. See doc for enforced config dependencies
A module install should not update config. If you want to update existing config, your module should implement hook_update_N()
(see docs) instead.
However, you could add a dependencies: enforced
section to your YML config files. This will remove your existing config on module uninstall, and install the newest config on module reinstall. This way you can "emulate" a simple update mechanism for your own, private custom module. See doc for enforced config dependencies
edited May 28 at 12:54
answered May 28 at 10:33
HudriHudri
2,6061 gold badge8 silver badges26 bronze badges
2,6061 gold badge8 silver badges26 bronze badges
add a comment
|
add a comment
|
You can update custom config with a settings form you build.
In a custom module custom_mailing add a file called custom_mailing.routing.yml add the following route:
custom_mailing.route_admin_settings:
path: '/admin/config/mailing'
defaults:
_title: 'Custom mailing'
_form: 'Drupalcustom_mailingFormAdminSettingsForm'
requirements:
_permission: 'administer custom_mailing settings'
Now I want a boolean value to be editable. I create a file in a map config/install
called custom_mailings.settings.yml with the following content:
mailsettings:
enabled: 0
In a module called custom_mailing. Inside src/Form
add file called AdminSettingsForm.php
.
<?php
namespace Drupalcustom_mailingForm;
use DrupalCoreFormConfigFormBase;
use DrupalCoreFormFormStateInterface;
/**
* Class AdminSettingsForm.
*
* @package Drupalcustom_mailingForm
*/
class AdminSettingsForm extends ConfigFormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'custom_mailing_admin_settings_form';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'custom_mailing.settings',
];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this->config('custom_mailing.settings');
$form['mailsettings'] = [
'#tree' => TRUE,
'#type' => 'fieldset',
'#title' => $this->t('Email settings'),
];
$form['mailsettings']['enabled'] = [
'#type' => 'checkbox',
'#title' => $this->t('Enable sending of e-mails.'),
'#default_value' => $config->get('mailsettings.enabled'),
];
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = $this->config('custom_mailing.settings');
$config->set('mailsettings', $form_state->getValue('mailsettings'));
$config->save();
parent::submitForm($form, $form_state);
}
}
Config will be deleted when disabling the module btw
– Stef Van Looveren
May 28 at 15:31
add a comment
|
You can update custom config with a settings form you build.
In a custom module custom_mailing add a file called custom_mailing.routing.yml add the following route:
custom_mailing.route_admin_settings:
path: '/admin/config/mailing'
defaults:
_title: 'Custom mailing'
_form: 'Drupalcustom_mailingFormAdminSettingsForm'
requirements:
_permission: 'administer custom_mailing settings'
Now I want a boolean value to be editable. I create a file in a map config/install
called custom_mailings.settings.yml with the following content:
mailsettings:
enabled: 0
In a module called custom_mailing. Inside src/Form
add file called AdminSettingsForm.php
.
<?php
namespace Drupalcustom_mailingForm;
use DrupalCoreFormConfigFormBase;
use DrupalCoreFormFormStateInterface;
/**
* Class AdminSettingsForm.
*
* @package Drupalcustom_mailingForm
*/
class AdminSettingsForm extends ConfigFormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'custom_mailing_admin_settings_form';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'custom_mailing.settings',
];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this->config('custom_mailing.settings');
$form['mailsettings'] = [
'#tree' => TRUE,
'#type' => 'fieldset',
'#title' => $this->t('Email settings'),
];
$form['mailsettings']['enabled'] = [
'#type' => 'checkbox',
'#title' => $this->t('Enable sending of e-mails.'),
'#default_value' => $config->get('mailsettings.enabled'),
];
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = $this->config('custom_mailing.settings');
$config->set('mailsettings', $form_state->getValue('mailsettings'));
$config->save();
parent::submitForm($form, $form_state);
}
}
Config will be deleted when disabling the module btw
– Stef Van Looveren
May 28 at 15:31
add a comment
|
You can update custom config with a settings form you build.
In a custom module custom_mailing add a file called custom_mailing.routing.yml add the following route:
custom_mailing.route_admin_settings:
path: '/admin/config/mailing'
defaults:
_title: 'Custom mailing'
_form: 'Drupalcustom_mailingFormAdminSettingsForm'
requirements:
_permission: 'administer custom_mailing settings'
Now I want a boolean value to be editable. I create a file in a map config/install
called custom_mailings.settings.yml with the following content:
mailsettings:
enabled: 0
In a module called custom_mailing. Inside src/Form
add file called AdminSettingsForm.php
.
<?php
namespace Drupalcustom_mailingForm;
use DrupalCoreFormConfigFormBase;
use DrupalCoreFormFormStateInterface;
/**
* Class AdminSettingsForm.
*
* @package Drupalcustom_mailingForm
*/
class AdminSettingsForm extends ConfigFormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'custom_mailing_admin_settings_form';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'custom_mailing.settings',
];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this->config('custom_mailing.settings');
$form['mailsettings'] = [
'#tree' => TRUE,
'#type' => 'fieldset',
'#title' => $this->t('Email settings'),
];
$form['mailsettings']['enabled'] = [
'#type' => 'checkbox',
'#title' => $this->t('Enable sending of e-mails.'),
'#default_value' => $config->get('mailsettings.enabled'),
];
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = $this->config('custom_mailing.settings');
$config->set('mailsettings', $form_state->getValue('mailsettings'));
$config->save();
parent::submitForm($form, $form_state);
}
}
You can update custom config with a settings form you build.
In a custom module custom_mailing add a file called custom_mailing.routing.yml add the following route:
custom_mailing.route_admin_settings:
path: '/admin/config/mailing'
defaults:
_title: 'Custom mailing'
_form: 'Drupalcustom_mailingFormAdminSettingsForm'
requirements:
_permission: 'administer custom_mailing settings'
Now I want a boolean value to be editable. I create a file in a map config/install
called custom_mailings.settings.yml with the following content:
mailsettings:
enabled: 0
In a module called custom_mailing. Inside src/Form
add file called AdminSettingsForm.php
.
<?php
namespace Drupalcustom_mailingForm;
use DrupalCoreFormConfigFormBase;
use DrupalCoreFormFormStateInterface;
/**
* Class AdminSettingsForm.
*
* @package Drupalcustom_mailingForm
*/
class AdminSettingsForm extends ConfigFormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'custom_mailing_admin_settings_form';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'custom_mailing.settings',
];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this->config('custom_mailing.settings');
$form['mailsettings'] = [
'#tree' => TRUE,
'#type' => 'fieldset',
'#title' => $this->t('Email settings'),
];
$form['mailsettings']['enabled'] = [
'#type' => 'checkbox',
'#title' => $this->t('Enable sending of e-mails.'),
'#default_value' => $config->get('mailsettings.enabled'),
];
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = $this->config('custom_mailing.settings');
$config->set('mailsettings', $form_state->getValue('mailsettings'));
$config->save();
parent::submitForm($form, $form_state);
}
}
edited Jun 4 at 15:06
answered May 28 at 15:30
Stef Van LooverenStef Van Looveren
1,0296 silver badges17 bronze badges
1,0296 silver badges17 bronze badges
Config will be deleted when disabling the module btw
– Stef Van Looveren
May 28 at 15:31
add a comment
|
Config will be deleted when disabling the module btw
– Stef Van Looveren
May 28 at 15:31
Config will be deleted when disabling the module btw
– Stef Van Looveren
May 28 at 15:31
Config will be deleted when disabling the module btw
– Stef Van Looveren
May 28 at 15:31
add a comment
|
Thanks for contributing an answer to Drupal Answers!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdrupal.stackexchange.com%2fquestions%2f281676%2fhow-can-i-update-existing-config-from-a-custom-modules-config-install-yamls%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I wouldn't recommend reinventing the Features module. But let's say this is a contrib module and you updated the install yamls that won't fire on sites that had that module installed already, you need to additionally provide your entity changes via
hook_update_N
programmatically.– leymannx
May 28 at 11:11
Maybe you can provide more details and context.
– leymannx
May 28 at 11:12