- var_dump: documentation ( source)
- class_uses: documentation ( source)
- in_array: documentation ( source)
<?php
interface FormStateInterface {}
class FormState implements FormStateInterface {}
class Config {}
class ConfigFormBase {
public function submitForm(array &$form, FormStateInterface $form_state) {
var_dump(in_array(ValidatableConfigFormTrait::class, class_uses($this)));
}
}
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());