public function WebformContentCreatorManageFieldsForm::validateForm in Webform Content Creator 3.x
Same name and namespace in other branches
- 8 src/Form/WebformContentCreatorManageFieldsForm.php \Drupal\webform_content_creator\Form\WebformContentCreatorManageFieldsForm::validateForm()
- 2.x src/Form/WebformContentCreatorManageFieldsForm.php \Drupal\webform_content_creator\Form\WebformContentCreatorManageFieldsForm::validateForm()
Form validation handler.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Overrides FormBase::validateForm
File
- src/
Form/ WebformContentCreatorManageFieldsForm.php, line 288
Class
- WebformContentCreatorManageFieldsForm
- Form handler for the Webform content creator manage fields form.
Namespace
Drupal\webform_content_creator\FormCode
public function validateForm(array &$form, FormStateInterface $form_state) {
parent::validateForm($form, $form_state);
$ct = $this->entity
->getContentType();
$content_type = $this->entityTypeManager
->getStorage('node_type')
->load($ct);
$node_fields = WebformContentCreatorUtilities::contentTypeFields($content_type);
$webform_id = $this->entity
->getWebform();
$webform_element_types = WebformContentCreatorUtilities::getWebformElementsTypes($webform_id);
// For each table row.
foreach ($form_state
->getValue(self::FORM_TABLE) as $k => $v) {
// Check if a content type field is selected.
if (!$v[self::CONTENT_TYPE_FIELD]) {
continue;
}
if (is_array($v[self::WEBFORM_FIELD])) {
$args = explode(',', $v[self::WEBFORM_FIELD]);
if (empty($args) || count($args) < 2) {
continue;
}
}
else {
foreach ($v[self::WEBFORM_FIELD] as $key => $component) {
$args = explode(',', $v[self::WEBFORM_FIELD][$key]);
if (empty($args) || count($args) < 2) {
continue;
}
}
}
$node_field_type = $node_fields[$k]
->getType();
$webform_option_type = array_key_exists($args[1], $webform_element_types) ? $webform_element_types[$args[1]] : '';
if ($node_field_type === $webform_option_type) {
continue;
}
}
}