Skip to content
This repository has been archived by the owner on Apr 17, 2024. It is now read-only.

Commit

Permalink
fix: allow install overrides using drush
Browse files Browse the repository at this point in the history
  • Loading branch information
GMSteuart authored and e0ipso committed Apr 29, 2019
1 parent 6f07a5e commit cfc6272
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
4 changes: 2 additions & 2 deletions contenta_jsonapi.profile
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ function _contenta_jsonapi_generate_keys() {
function contenta_jsonapi_module_install(array &$install_state) {
set_time_limit(0);

$extensions = $install_state['contenta_jsonapi_additional_modules'];
$form_values = $install_state['form_state_values'];
$extensions = $install_state['forms']['contenta_jsonapi_additional_modules'];
$form_values = $install_state['forms']['form_state_values'];

$optional_modules_manager = \Drupal::service('plugin.manager.contenta_jsonapi.optional_modules');
$definitions = array_map(function ($extension_name) use ($optional_modules_manager) {
Expand Down
39 changes: 20 additions & 19 deletions src/Installer/Form/ModuleConfigureForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public function getFormId() {
* {@inheritdoc}
*/
protected function getEditableConfigNames() {

return [];
}

Expand Down Expand Up @@ -87,8 +86,8 @@ public function buildForm(array $form, FormStateInterface $form_state) {

$form = $instance->buildForm($form, $form_state);
}
$form['#title'] = $this->t('Install & configure modules');

$form['#title'] = $this->t('Install & configure modules');
$form['actions'] = ['#type' => 'actions'];
$form['actions']['save'] = [
'#type' => 'submit',
Expand All @@ -104,25 +103,27 @@ public function buildForm(array $form, FormStateInterface $form_state) {
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$install_modules = [];

foreach ($form_state->getValues() as $key => $value) {

if (strpos($key, 'install_modules') !== FALSE && $value) {
preg_match('/install_modules_(?P<name>\w+)/', $key, $values);
$install_modules[] = $values['name'];
}
}

// Get forms from build info to allow for drush overrides
// on default form_state->getValue() that are sent.
$build_info = $form_state->getBuildInfo();
$install_state = $build_info['args'][0]['forms'];

// Determine form state based off override existence.
$install_state['form_state_values'] = isset($install_state['form_state_values'])
? $install_state['form_state_values']
: [];
$install_state['form_state_values'] += $form_state->getValues();

// Iterate over the form state values to determine modules to install.
$values = array_filter($install_state['form_state_values']);
$module_values = array_filter(array_keys($values), function ($key) {
return strpos($key, 'install_modules_') !== FALSE;
});
$install_state['contenta_jsonapi_additional_modules'] = array_map(function ($name) {
return substr($name, strlen('install_modules_'));
}, $module_values);

$install_state = $build_info['args'];

$install_state[0]['contenta_jsonapi_additional_modules'] = $install_modules;
$install_state[0]['form_state_values'] = $form_state->getValues();

$build_info['args'] = $install_state;

$build_info['args'][0]['forms'] = $install_state;
$form_state->setBuildInfo($build_info);
}

Expand Down

0 comments on commit cfc6272

Please sign in to comment.