protected function WebformSubmissionDevelGenerateTrait::validateEntity in Webform 8.5
Same name and namespace in other branches
- 6.x src/Plugin/DevelGenerate/WebformSubmissionDevelGenerateTrait.php \Drupal\webform\Plugin\DevelGenerate\WebformSubmissionDevelGenerateTrait::validateEntity()
Validate webform source entity type and id.
Parameters
array $webform_ids: An array webform 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 WebformSubmissionDevelGenerateTrait::validateEntity()
- WebformSubmissionDevelGenerateTrait::validateForm in src/
Plugin/ DevelGenerate/ WebformSubmissionDevelGenerateTrait.php - Custom validation handler.
- WebformSubmissionDevelGenerateTrait::_validateDrushParams in src/
Plugin/ DevelGenerate/ WebformSubmissionDevelGenerateTrait.php
File
- src/
Plugin/ DevelGenerate/ WebformSubmissionDevelGenerateTrait.php, line 472
Class
- WebformSubmissionDevelGenerateTrait
- Provides a WebformSubmissionDevelGenerate trait.
Namespace
Drupal\webform\Plugin\DevelGenerateCode
protected function validateEntity(array $webform_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();
$webform_field_name = $this->webformEntityReferenceManager
->getFieldName($source_entity);
if (!$webform_field_name) {
return $t("'@title' (@entity_type:@entity_id) does not have a 'webform' field.", $dt_args);
}
if (count($webform_ids) > 1) {
return $t("'@title' (@entity_type:@entity_id) can only be associated with a single webform.", $dt_args);
}
$dt_args['@webform_ids'] = WebformArrayHelper::toString($webform_ids, $t('or'));
if (!in_array($source_entity->webform->target_id, $webform_ids)) {
return $t("'@title' (@entity_type:@entity_id) does not have a '@webform_ids' webform associated with it.", $dt_args);
}
return NULL;
}