Giter Site home page Giter Site logo

Comments (3)

mrkmiller avatar mrkmiller commented on August 29, 2024

This is probably the most standard form of reverting configuration back to code:

/** @var \Drupal\config_update\ConfigRevertInterface $config_revert */
$config_revert = \Drupal::service('config_update.config_update');
$config_revert->revert('entity_view_display', 'node.sf_person.teaser'); // revert person teaser

Doing this will revert the configuration wherever it is stored. So it shouldn't matter if I subprofile is overriding config.

Manually setting config could be a little more tricky. What happens if the base profile tries to manually update the "contributor" user role with a new permission when the subprofile has removed it?

// Set Permissions config for contributor users
$config = \Drupal::service('config.factory')->getEditable('user.role.contributor');
$permissions = $config->get('permissions');
$permissions[] = 'new permission setting';
$config->set('permissions', $permissions)->save();

I'll try this out.

from sitefarm_seed.

mrkmiller avatar mrkmiller commented on August 29, 2024

Trying to get config for a missing role or any missing config just returns NULL

$config = \Drupal::service('config.factory')->getEditable('user.role.missingrole');
$permissions = $config->get('permissions');
// Returns NULL

So a conditional should be applied in update hooks to see if there is config present before settings new config.

If a random config item is attempted to be fetched that Drupal knows nothing about then an Exception occurs when attempting to save. So a conditional/try-catch is needed.

$config = \Drupal::service('config.factory')->getEditable('randomconfigitems');
$someconfig = $config->get('someconfig');
$someconfig[] = 'new config setting';
$config->set('someconfig', $someconfig)->save();

Throws
Drupal\Core\Config\ConfigNameException: Missing namespace in Config object name randomconfigitems. in Drupal\Core\Config\ConfigBase::validateName() (line 97 of core/lib/Drupal/Core/Config/ConfigBase.php).

To fix this use:

$config = \Drupal::service('config.factory')->getEditable('randomconfigitems');
$someconfig = $config->get('someconfig');
if ($someconfig) {
  $someconfig[] = 'new config setting';
  $config->set('someconfig', $someconfig)->save();
}

or

try {
  $config = \Drupal::service('config.factory')->getEditable('randomconfigitems');
  $someconfig = $config->get('someconfig');
  $someconfig[] = 'new config setting';
  $config->set('someconfig', $someconfig)->save();
} catch (Exception $e) {
  // Do something with the "Missing namespace in Config object name randomconfigitems." error.
}

from sitefarm_seed.

mrkmiller avatar mrkmiller commented on August 29, 2024

NO

I think config items need to be checked if manually altering config. Otherwise just reverting whole config files is fine.

from sitefarm_seed.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.