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;
}








1

















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 ?










share|improve this question





























  • 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


















1

















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 ?










share|improve this question





























  • 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














1












1








1


1






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 ?










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question



share|improve this question








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 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



















  • 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

















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










2 Answers
2






active

oldest

votes


















2


















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






share|improve this answer




































    0


















    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);
    }

    }





    share|improve this answer





























    • Config will be deleted when disabling the module btw

      – Stef Van Looveren
      May 28 at 15:31













    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
    });


    }
    });















    draft saved

    draft discarded
















    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









    2


















    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






    share|improve this answer

































      2


















      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






      share|improve this answer































        2














        2










        2









        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






        share|improve this answer
















        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







        share|improve this answer















        share|improve this answer




        share|improve this answer



        share|improve this answer








        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




























            0


















            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);
            }

            }





            share|improve this answer





























            • Config will be deleted when disabling the module btw

              – Stef Van Looveren
              May 28 at 15:31
















            0


















            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);
            }

            }





            share|improve this answer





























            • Config will be deleted when disabling the module btw

              – Stef Van Looveren
              May 28 at 15:31














            0














            0










            0









            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);
            }

            }





            share|improve this answer
















            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);
            }

            }






            share|improve this answer















            share|improve this answer




            share|improve this answer



            share|improve this answer








            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



















            • 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



















            draft saved

            draft discarded



















































            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.




            draft saved


            draft discarded














            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





















































            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









            Popular posts from this blog

            He _____ here since 1970 . Answer needed [closed]What does “since he was so high” mean?Meaning of “catch birds for”?How do I ensure “since” takes the meaning I want?“Who cares here” meaningWhat does “right round toward” mean?the time tense (had now been detected)What does the phrase “ring around the roses” mean here?Correct usage of “visited upon”Meaning of “foiled rail sabotage bid”It was the third time I had gone to Rome or It is the third time I had been to Rome

            Bunad

            Færeyskur hestur Heimild | Tengill | Tilvísanir | LeiðsagnarvalRossið - síða um færeyska hrossið á færeyskuGott ár hjá færeyska hestinum