function prod_check_synchronize_prod_check_processors in Production check & Production monitor 8
Helper function to synchronize prod check processor plugins and entities
1 call to prod_check_synchronize_prod_check_processors()
- prod_check_cache_flush in ./
prod_check.module - Implements hook_cache_flush().
File
- ./
prod_check.module, line 147 - Module file for the prod check module
Code
function prod_check_synchronize_prod_check_processors() {
// This isn't a nice way but at the moment it's the only way I can think of to keep the one on one relation between
// prod check entities and plugins intact. As the amount of checks will stay limited this isn't a performance issue.
$query = \Drupal::entityQuery('prod_check_processor')
->condition('status', 1);
$existing_processor = $query
->execute();
$processors = \Drupal::service('plugin.manager.prod_check_processor')
->getDefinitions();
foreach ($processors as $processor) {
if (!isset($existing_processor[$processor['id']])) {
$values = [
'id' => $processor['id'],
'label' => (string) $processor['title'],
];
/** @var ProdCheckEntity $new_check */
$new_check = \Drupal::entityTypeManager()
->getStorage('prod_check_processor')
->create($values);
$new_check
->setPlugin($processor['id']);
$new_check
->save();
}
}
}