<?php
interface FormStateInterface {}
class FormState implements FormStateInterface {}
class Config {}
class ConfigFormBase {
public function submitForm(array &$form, FormStateInterface $form_state) {
var_dump(method_exists($this, 'mapFormValuesToConfig'));
}
}
trait ValidatableConfigFormTrait {
abstract protected static function mapFormValuesToConfig(FormStateInterface $form_state, Config $config): void;
}
class MyForm extends ConfigFormBase {
use ValidatableConfigFormTrait;
protected static function mapFormValuesToConfig(FormStateInterface $form_state, Config $config): void {
// without this, PHP will complain! 👍
}
}
class SubMyForm extends MyForm {}
$form = [];
(new MyForm())->submitForm($form, new FormState());
(new SubMyForm())->submitForm($form, new FormState());