function system_authorized_init in Drupal 8
Same name and namespace in other branches
- 7 modules/system/system.module \system_authorized_init()
- 9 core/modules/system/system.module \system_authorized_init()
- 10 core/modules/system/system.module \system_authorized_init()
Setup a given callback to run via authorize.php with elevated privileges.
To use authorize.php, certain variables must be stashed in the user's session. This function sets up all the necessary session variables. The calling function should then redirect to authorize.php, using the full path returned by system_authorized_get_url(). That initiates the workflow that will eventually lead to the callback being invoked. The callback will be invoked at a low bootstrap level, without all modules being invoked, so it needs to be careful not to assume any code exists. Example (system_authorized_run()):
system_authorized_init($callback, $file, $arguments, $page_title);
return new RedirectResponse(system_authorized_get_url()
->toString());
Example (update_manager_install_form_submit()):
system_authorized_init('update_authorize_run_install', drupal_get_path('module', 'update') . '/update.authorize.inc', $arguments, t('Update manager'));
$form_state
->setRedirectUrl(system_authorized_get_url());
Parameters
callable $callback: The name of the function to invoke once the user authorizes the operation.
$file: The full path to the file where the callback function is implemented.
$arguments: Optional array of arguments to pass into the callback when it is invoked. Note that the first argument to the callback is always the FileTransfer object created by authorize.php when the user authorizes the operation.
$page_title: Optional string to use as the page title once redirected to authorize.php.
Return value
Nothing, this function just initializes variables in the user's session.
Related topics
4 calls to system_authorized_init()
- SystemTestController::authorizeInit in core/
modules/ system/ tests/ modules/ system_test/ src/ Controller/ SystemTestController.php - Initialize authorize.php during testing.
- system_authorized_run in core/
modules/ system/ system.module - Setup and invoke an operation using authorize.php.
- UpdateManagerInstall::submitForm in core/
modules/ update/ src/ Form/ UpdateManagerInstall.php - Form submission handler.
- UpdateReady::submitForm in core/
modules/ update/ src/ Form/ UpdateReady.php - Form submission handler.
File
- core/
modules/ system/ system.module, line 480 - Configuration system that lets administrators modify the workings of the site.
Code
function system_authorized_init($callback, $file, $arguments = [], $page_title = NULL) {
$session = \Drupal::request()
->getSession();
// First, figure out what file transfer backends the site supports, and put
// all of those in the SESSION so that authorize.php has access to all of
// them via the class autoloader, even without a full bootstrap.
$session
->set('authorize_filetransfer_info', drupal_get_filetransfer_info());
// Now, define the callback to invoke.
$session
->set('authorize_operation', [
'callback' => $callback,
'file' => $file,
'arguments' => $arguments,
]);
if (isset($page_title)) {
$session
->set('authorize_page_title', $page_title);
}
}