-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #113 from discoverygarden/fix/suppressed-config
DDST-376: Fix/suppress config
- Loading branch information
Showing
11 changed files
with
202 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
--- | ||
binary_directory_whitelist: [] | ||
schemes: [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Post-update hooks. | ||
*/ | ||
|
||
/** | ||
* Set a value for islandora_spreadsheet_ingest.settings:schemes, if unset. | ||
*/ | ||
function islandora_spreadsheet_ingest_post_update_set_default_schemes(&$sandbox) { | ||
$config = \Drupal::configFactory()->getEditable('islandora_spreadsheet_ingest.settings'); | ||
if ($config->get('schemes') === NULL) { | ||
$config->set('schemes', [])->save(); | ||
return \t('Set default value of an empty array for islandora_spreadsheet_ingest.settings:schemes.'); | ||
} | ||
return \t('A value is already present for islandora_spreadsheet_ingest.settings:schemes.'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
src/EventSubscriber/ConfigTransformationEventSubscriber.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<?php | ||
|
||
namespace Drupal\islandora_spreadsheet_ingest\EventSubscriber; | ||
|
||
use Drupal\Core\Config\ConfigEvents; | ||
use Drupal\Core\Config\StorageInterface; | ||
use Drupal\Core\Config\StorageTransformEvent; | ||
use Drupal\Core\DependencyInjection\ContainerInjectionInterface; | ||
use Symfony\Component\DependencyInjection\ContainerInterface; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
|
||
/** | ||
* Config transformation event subscriber. | ||
* | ||
* Inspired by https://www.drupal.org/sandbox/ekes/3187856, which deals instead | ||
* with "webform" entities. | ||
*/ | ||
class ConfigTransformationEventSubscriber implements EventSubscriberInterface, ContainerInjectionInterface { | ||
|
||
/** | ||
* Constructor. | ||
*/ | ||
public function __construct( | ||
protected StorageInterface $activeStorage, | ||
) { | ||
// No-op. | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public static function create(ContainerInterface $container) { | ||
return new static( | ||
$container->get('config.storage'), | ||
); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public static function getSubscribedEvents() : array { | ||
return [ | ||
ConfigEvents::STORAGE_TRANSFORM_EXPORT => 'onExportTransform', | ||
ConfigEvents::STORAGE_TRANSFORM_IMPORT => 'onImportTransform', | ||
]; | ||
} | ||
|
||
/** | ||
* Config export event handler. | ||
* | ||
* @param \Drupal\Core\Config\StorageTransformEvent $event | ||
* The event to which to respond. | ||
*/ | ||
public function onExportTransform(StorageTransformEvent $event) : void { | ||
$storage = $event->getStorage(); | ||
foreach ($this->toIgnore($storage) as $name) { | ||
$storage->delete($name); | ||
} | ||
} | ||
|
||
/** | ||
* Config import event handler. | ||
* | ||
* @param \Drupal\Core\Config\StorageTransformEvent $event | ||
* The event to which to respond. | ||
*/ | ||
public function onImportTransform(StorageTransformEvent $event) : void { | ||
$storage = $event->getStorage(); | ||
|
||
$inbound = iterator_to_array(static::toIgnore($storage), FALSE); | ||
$current = iterator_to_array(static::toIgnore($this->activeStorage), FALSE); | ||
|
||
// In case a config object escaped let's deal with it. | ||
foreach (array_diff($inbound, $current) as $to_delete) { | ||
$storage->delete($to_delete); | ||
} | ||
|
||
// Keep the current config as the current config. | ||
foreach ($current as $to_maintain) { | ||
$storage->write($to_maintain, $this->activeStorage->read($to_maintain)); | ||
} | ||
} | ||
|
||
/** | ||
* Helper; yield all the configs that should not change on imports/exports. | ||
* | ||
* @param \Drupal\Core\Config\StorageInterface $storage | ||
* The storage from which to enumerate configs. | ||
* | ||
* @return \Generator | ||
* The names of the configs that should never be changed on imports/exports. | ||
*/ | ||
protected static function toIgnore(StorageInterface $storage) : \Generator { | ||
yield from $storage->listAll('migrate_plus.migration.isi__'); | ||
yield from $storage->listAll('migrate_plus.migration_group.isi__'); | ||
yield from $storage->listAll('islandora_spreadsheet_ingest.request.'); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.