Skip to content

Instantly share code, notes, and snippets.

@amcgowanca
Created November 25, 2017 13:42
Show Gist options
  • Save amcgowanca/a74d340e39ce23a146e4d52df4723f8f to your computer and use it in GitHub Desktop.
Save amcgowanca/a74d340e39ce23a146e4d52df4723f8f to your computer and use it in GitHub Desktop.
Drupal 8: Exclude single modules from always writing to core.extension.yml
<?php
namespace Drupal\module_name\Plugin\ConfigFilter;
use Drupal\config_filter\Plugin\ConfigFilterBase;
/**
* Excludes a set of extensions from exporting to core.extension.yml.
*
* @ConfigFilter(
* id = "module_name_exclude_extension",
* label = "Excludes a set of extensions from core.extension.yml.",
* weight = 10
* )
*/
class ExcludeExtensions extends ConfigFilterBase {
/**
* {@inheritdoc}
*/
public function filterWrite($name, array $data) {
if ($name == 'core.extension' && isset($data['module'])) {
foreach ($this->getExtensionModules() as $module_name) {
if (isset($data['module'][$module_name])) {
unset($data['module'][$module_name]);
}
}
}
return parent::filterWrite($name, $data);
}
/**
* Returns an array of modules to exclude.
*
* @return array
* An array of module names.
*/
protected function getExtensionModules() {
return ['default_content'];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment