Skip to content

Commit

Permalink
UHF-9256: Install the debug rest config during module install.
Browse files Browse the repository at this point in the history
  • Loading branch information
khalima committed Nov 8, 2023
1 parent cd300f7 commit 82fbd82
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions helfi_api_base.install
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,37 @@ function helfi_api_base_install() : void {
]);
}

// Install the debug rest config.
helfi_api_base_install_debug_rest_config();

// Create debug_api role.
if (!$role = Role::load('debug_api')) {
$role = Role::create(['label' => 'Debug API', 'id' => 'debug_api']);
}

// Grant the restful get helfi_debug_data permission.
$role->grantPermission('restful get helfi_debug_data')
->save();
}
catch (\InvalidArgumentException) {
}
}

/**
* Install the debug rest config.
*/
function helfi_api_base_install_debug_rest_config() : void {
/** @var \Drupal\Core\Extension\ExtensionPathResolver $extensionPathResolver */
$extensionPathResolver = Drupal::service('extension.path.resolver');
$config_path = $extensionPathResolver->getPath('module', 'helfi_api_base') . '/config/optional';
$source = new FileStorage($config_path);
$config_storage = Drupal::service('config.storage');

// Install rest resource config.
$config_name = 'rest.resource.helfi_debug_data';
$config_storage->write($config_name, $source->read($config_name));
}

/**
* Enable 'helfi_link_converter' filter format.
*/
Expand All @@ -69,15 +90,7 @@ function helfi_api_base_update_9002() : void {
if (!Drupal::moduleHandler()->moduleExists('rest')) {
return;
}
/** @var \Drupal\Core\Extension\ExtensionPathResolver $extensionPathResolver */
$extensionPathResolver = Drupal::service('extension.path.resolver');
$config_path = $extensionPathResolver->getPath('module', 'helfi_api_base') . '/config/optional';
$source = new FileStorage($config_path);
$config_storage = Drupal::service('config.storage');

// Install rest resource config.
$config_name = 'rest.resource.helfi_debug_data';
$config_storage->write($config_name, $source->read($config_name));
helfi_api_base_install_debug_rest_config();
}

/**
Expand Down

0 comments on commit 82fbd82

Please sign in to comment.