public static function GeofieldMapFieldTrait::customMapStyleValidate in Geofield Map 8
Form element validation handler for a Custom Map Style Name Required.
File
- src/
GeofieldMapFieldTrait.php, line 261
Class
- GeofieldMapFieldTrait
- Class GeofieldMapFieldTrait.
Namespace
Drupal\geofield_mapCode
public static function customMapStyleValidate($element, FormStateInterface &$form_state) {
// Get to the actual values in a form tree.
$parents = $element['#parents'];
$values = $form_state
->getValues();
for ($i = 0; $i < count($parents) - 1; $i++) {
$values = $values[$parents[$i]];
}
if ($values['custom_style_control'] && empty($element['#value'])) {
$form_state
->setError($element, t('The @field cannot be empty.', [
'@field' => $element['#title'],
]));
}
}