private function ExampleCustomInput::lookupVoucherCodeEntity in Extra Field 8.2
Lookup the voucher entity that corresponds with a given code.
Parameters
string $code: The voucher code.
Return value
\Drupal\my_voucher_code\VoucherCodeInterface|null The voucher entity. Null if no entity exists for this code.
1 call to ExampleCustomInput::lookupVoucherCodeEntity()
- ExampleCustomInput::validateVoucherCode in modules/
extra_field_example/ src/ Plugin/ ExtraField/ Form/ ExampleCustomInput.php - Field validation callback for voucher code.
File
- modules/
extra_field_example/ src/ Plugin/ ExtraField/ Form/ ExampleCustomInput.php, line 126
Class
- ExampleCustomInput
- Example Extra field form display.
Namespace
Drupal\extra_field_example\Plugin\ExtraField\FormCode
private function lookupVoucherCodeEntity($code) {
if (empty($code)) {
return NULL;
}
/** @var \Drupal\my_voucher\VoucherInterface[] $vouchers */
$vouchers = $this->entityTypeManager
->getStorage('voucher')
->loadByProperties([
'code' => trim($code),
]);
return empty($vouchers) ? NULL : reset($vouchers);
}