public function GetServices::getFieldValidation in Simple Node Importer 8
2 calls to GetServices::getFieldValidation()
- GetServices::checkFieldWidget in src/
Services/ GetServices.php - Checks the widget type of each field.
- GetServices::prepareEntityReferenceFieldData in src/
Services/ GetServices.php
File
- src/
Services/ GetServices.php, line 644
Class
Namespace
Drupal\simple_node_importer\ServicesCode
public function getFieldValidation($fieldType, $field_data, $fieldIsRequired = FALSE) {
$flag = TRUE;
// $k = 0;.
if (is_array($field_data) && $fieldIsRequired == TRUE) {
foreach ($field_data as $key => $fieldVal) {
$flags[$key] = empty($fieldVal) ? FALSE : TRUE;
}
if (!in_array(TRUE, $flags)) {
return $flag = FALSE;
}
}
if (empty($field_data) && $fieldIsRequired == TRUE) {
return $flag = FALSE;
}
elseif (!empty($field_data)) {
switch ($fieldType) {
case 'email':
$flg = 0;
if (is_array($field_data)) {
foreach ($field_data as $fieldData) {
if (!empty($fieldData) && filter_var($fieldData, FILTER_VALIDATE_EMAIL) != FALSE) {
$flg = 1;
}
elseif (!empty($fieldData)) {
return $flag = FALSE;
}
}
$flag = $flg == 0 && $fieldIsRequired == TRUE ? FALSE : TRUE;
}
else {
if (!empty($field_data) && filter_var($field_data, FILTER_VALIDATE_EMAIL) != FALSE) {
$flag = TRUE;
}
elseif (empty($field_data) && $fieldIsRequired == FALSE) {
$flag = TRUE;
}
else {
$flag = FALSE;
}
}
break;
case 'image':
case 'link':
$flg = 0;
if (is_array($field_data)) {
foreach ($field_data as $fieldData) {
if (!empty($fieldData) && filter_var($fieldData, FILTER_VALIDATE_URL) != FALSE) {
$flg = 1;
}
elseif (!empty($fieldData)) {
return $flag = FALSE;
}
}
$flag = $flg == 0 && $fieldIsRequired == TRUE ? FALSE : TRUE;
}
else {
if (!empty($field_data) && filter_var($field_data, FILTER_VALIDATE_URL) != FALSE) {
$flag = TRUE;
}
elseif (empty($field_data) && $fieldIsRequired == FALSE) {
$flag = TRUE;
}
else {
$flag = FALSE;
}
}
break;
}
}
return $flag;
}