I have created a form following structure:
my_module
|__
src
|__Form
|__myform.php
I want to get the form_state in some()
function in controller located at:
my_module
|__
src
|__Controller
|__mycontroller.php
So that I can set error on one of my form element (say) - upload_container
. And I will call function some()
:
static function some() {
$form_state->setErrorByName('upload_container', 'throw error while validating form');
}
here shown below as (in myform.php):
public function validateForm(array &$form, FormStateInterface $form_state) {
mycontroller::some();
}
In D7, we do the same thing in a separate file example: common.inc
static function some() {
form_set_error('upload_container', 'throw error while validating form');
}
But in D8, How to set error on a form element via function located somewhere in controller file? I can't even get form_state in any third function which is located at controller.