protected function YamlFormSubmissionDevelGenerate::validateEntity in YAML Form 8
Validate form source entity type and id.
Parameters
array $yamlform_ids: An array form ids.
string $entity_type: An entity type.
int $entity_id: An entity id.
Return value
string An error message or NULL if there are no validation errors.
2 calls to YamlFormSubmissionDevelGenerate::validateEntity()
- YamlFormSubmissionDevelGenerate::validateDrushParams in src/
Plugin/ DevelGenerate/ YamlFormSubmissionDevelGenerate.php - YamlFormSubmissionDevelGenerate::validateForm in src/
Plugin/ DevelGenerate/ YamlFormSubmissionDevelGenerate.php - Custom validation handler.
File
- src/
Plugin/ DevelGenerate/ YamlFormSubmissionDevelGenerate.php, line 359
Class
- YamlFormSubmissionDevelGenerate
- Provides a YamlFormSubmissionDevelGenerate plugin.
Namespace
Drupal\yamlform\Plugin\DevelGenerateCode
protected function validateEntity(array $yamlform_ids, $entity_type, $entity_id) {
$t = function_exists('dt') ? 'dt' : 't';
if (!$entity_type) {
return $t('Entity type is required');
}
if (!$entity_id) {
return $t('Entity id is required');
}
$dt_args = [
'@entity_type' => $entity_type,
'@entity_id' => $entity_id,
];
$source_entity = $this->entityTypeManager
->getStorage($entity_type)
->load($entity_id);
if (!$source_entity) {
return $t('Unable to load @entity_type:@entity_id', $dt_args);
}
$dt_args['@title'] = $source_entity
->label();
if (!method_exists($source_entity, 'hasField') || !$source_entity
->hasField('yamlform')) {
return $t("'@title' (@entity_type:@entity_id) does not have a 'yamlform' field.", $dt_args);
}
if (count($yamlform_ids) > 1) {
return $t("'@title' (@entity_type:@entity_id) can only be associated with a single form.", $dt_args);
}
$dt_args['@yamlform_ids'] = YamlFormArrayHelper::toString($yamlform_ids, $t('or'));
if (!in_array($source_entity->yamlform->target_id, $yamlform_ids)) {
return $t("'@title' (@entity_type:@entity_id) does not have a '@yamlform_ids' yamlform associated with it.", $dt_args);
}
return NULL;
}