Created
November 3, 2022 08:39
-
-
Save Seorusus/8d5920a884da74f037c31a9cfdc4daa1 to your computer and use it in GitHub Desktop.
Валидация поля. Если количество элементов менее 2. Получение количества IDs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Validate Carousel gallery paragraph. | |
* | |
* @param array $element | |
* Reference form array. | |
* | |
* @param \Drupal\Core\Form\FormStateInterface $formState | |
* Form state object. | |
*/ | |
function basf_site_validate_carousel_gallery( | |
array &$element, | |
FormStateInterface $formState | |
): void { | |
$subItems = $element["subform"]["field_gallery_slides"]["widget"]["selection"]; | |
// Gets count of slides. | |
$str = implode(",", array_keys($subItems)); | |
$subItems = preg_replace('/[^0-9.]+/', '', $str); | |
if (count(str_split($subItems)) < 2) { | |
$error = t('At least 2 media sliders is required.'); | |
$formState->setError($element, $error); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment