@@ -54,7 +54,6 @@ public function getFormId() {
5454 * {@inheritdoc}
5555 */
5656 protected function getEditableConfigNames () {
57-
5857 return [];
5958 }
6059
@@ -87,8 +86,8 @@ public function buildForm(array $form, FormStateInterface $form_state) {
8786
8887 $ form = $ instance ->buildForm ($ form , $ form_state );
8988 }
90- $ form ['#title ' ] = $ this ->t ('Install & configure modules ' );
9189
90+ $ form ['#title ' ] = $ this ->t ('Install & configure modules ' );
9291 $ form ['actions ' ] = ['#type ' => 'actions ' ];
9392 $ form ['actions ' ]['save ' ] = [
9493 '#type ' => 'submit ' ,
@@ -104,25 +103,27 @@ public function buildForm(array $form, FormStateInterface $form_state) {
104103 * {@inheritdoc}
105104 */
106105 public function submitForm (array &$ form , FormStateInterface $ form_state ) {
107- $ install_modules = [];
108-
109- foreach ($ form_state ->getValues () as $ key => $ value ) {
110-
111- if (strpos ($ key , 'install_modules ' ) !== FALSE && $ value ) {
112- preg_match ('/install_modules_(?P<name>\w+)/ ' , $ key , $ values );
113- $ install_modules [] = $ values ['name ' ];
114- }
115- }
116-
106+ // Get forms from build info to allow for drush overrides
107+ // on default form_state->getValue() that are sent.
117108 $ build_info = $ form_state ->getBuildInfo ();
109+ $ install_state = $ build_info ['args ' ][0 ]['forms ' ];
110+
111+ // Determine form state based off override existence.
112+ $ install_state ['form_state_values ' ] = isset ($ install_state ['form_state_values ' ])
113+ ? $ install_state ['form_state_values ' ]
114+ : [];
115+ $ install_state ['form_state_values ' ] += $ form_state ->getValues ();
116+
117+ // Iterate over the form state values to determine modules to install.
118+ $ values = array_filter ($ install_state ['form_state_values ' ]);
119+ $ module_values = array_filter (array_keys ($ values ), function ($ key ) {
120+ return strpos ($ key , 'install_modules_ ' ) !== FALSE ;
121+ });
122+ $ install_state ['contenta_jsonapi_additional_modules ' ] = array_map (function ($ name ) {
123+ return substr ($ name , strlen ('install_modules_ ' ));
124+ }, $ module_values );
118125
119- $ install_state = $ build_info ['args ' ];
120-
121- $ install_state [0 ]['contenta_jsonapi_additional_modules ' ] = $ install_modules ;
122- $ install_state [0 ]['form_state_values ' ] = $ form_state ->getValues ();
123-
124- $ build_info ['args ' ] = $ install_state ;
125-
126+ $ build_info ['args ' ][0 ]['forms ' ] = $ install_state ;
126127 $ form_state ->setBuildInfo ($ build_info );
127128 }
128129
0 commit comments