public static function Pool::createPool in CMS Content Sync 2.0.x
Same name and namespace in other branches
- 8 src/Entity/Pool.php \Drupal\cms_content_sync\Entity\Pool::createPool()
- 2.1.x src/Entity/Pool.php \Drupal\cms_content_sync\Entity\Pool::createPool()
Create a pool configuration programmatically.
Parameters
$pool_name:
string $pool_id:
$backend_url:
$authentication_type:
1 call to Pool::createPool()
- MigrationBase::createPools in modules/
cms_content_sync_migrate_acquia_content_hub/ src/ Form/ MigrationBase.php - Create the pools based on the user selected terms.
File
- src/
Entity/ Pool.php, line 490
Class
- Pool
- Defines the "Content Sync - Pool" entity.
Namespace
Drupal\cms_content_sync\EntityCode
public static function createPool($pool_name, $pool_id, $backend_url, $authentication_type) {
// If no pool_id is given, create one.
if (empty($pool_id)) {
$pool_id = strtolower($pool_name);
$pool_id = preg_replace('@[^a-z0-9_]+@', '_', $pool_id);
}
$pools = Pool::getAll();
if (array_key_exists($pool_id, $pools)) {
\Drupal::messenger()
->addMessage('A pool with the machine name ' . $pool_id . ' does already exist. Therefor the creation has been skipped.', 'warning');
}
else {
$uuid_service = \Drupal::service('uuid');
$language_manager = \Drupal::service('language_manager');
$default_language = $language_manager
->getDefaultLanguage();
$pool_config = \Drupal::service('config.factory')
->getEditable('cms_content_sync.pool.' . $pool_id);
$pool_config
->set('uuid', $uuid_service
->generate())
->set('langcode', $default_language
->getId())
->set('status', true)
->set('id', $pool_id)
->set('label', $pool_name)
->set('backend_url', $backend_url)
->set('authentication_type', $authentication_type)
->save();
}
return $pool_id;
}