Drupal 10, the latest version of the open-source digital experience platform with even more features, is here.Hello there,
I'm working on hosting_platform_git and provision_platform_git. I'm not sure how to pass data from the frontend to the backend, and everything I've tried hasn't worked.
Here's what I have:
hosting_platform_git.drush.inc:
// At this point, I know that $task->ref->git contains the right data (I've checked this and it works),
// so I'm following the example of other parts of hosting module and using $task->context_options
// to pass the data to the backend?
function hosting_hosting_platform_git_context_options(&$task) {
$task->context_options['deploy_from_git'] = FALSE;
if (isset($task->ref->git['repo_url']) && $task->ref->git['repo_url'] != 'NOOP') {
$task->context_options['deploy_from_git'] = TRUE;
$task->context_options['repo_url'] = $task->ref->git['repo_url'];
$task->context_options['repo_branch'] = $task->ref->git['repo_branch'];
}
}
Here's my problem, though:
provision_platform_git.drush.inc:
// This function gets called at the correct point in execution (if I clone from git here, verification will pass)
// I'm just not sure what to put below drush_log('CALLED') to get the data that I set in $task->context_options in the frontend.
function drush_provision_platform_git_provision_verify_validate() {
if (d()->type === 'platform') {
drush_log('CALLED');
// QUESTION: What do I put here to get the context data I passed in?
drush_log(print_r(d(), TRUE));
if (!provision_file()->exists(d()->root)->status() && !empty(d()->provision_from_git)) {
drush_log(dt("Platform path does not exist, cloning from Git"));
drush_log(dt("Executing: " . 'git clone --recursive ' . excapeshellarg(trim(d()->repo_url)) . '--branch ' . escapeshellarg(trim(d()->repo_branch)) . ' ' . d()->root));
// Clone the repo
$output = exec('git clone --recursive -v' . excapeshellarg(trim(d()->repo_url)) . '--branch ' . escapeshellarg(trim(d()->repo_branch) . ' ' . d()->root), $output, $return_value);
if ($return_value === 0) {
drush_log(dt("Platform successfully cloned from Git"));
}
else {
// We send back the full output if something went wrong.
return drush_set_error("GIT_CLONE_FAILED", "Could not clone git repository. Output from Git: " . $output);
}
}
}
}
Am I just doing something wrong here? Or not understanding how things fit together?










Comments
Comment #1
cweagansNevermind, I got it figured out. See hosting_platform_git and provision_platform_git for example :)
Comment #2
ergonlogicNote that devshop does something similar (putting the whole platform under git), and provides a bunch of other functionality too.
For those curious about how this is done, you need to implement a Provision Service in order to persist data in a Context. See the extensions mentioned above, as they are good minimalist examples of this technique.