public static function PrivateMessageThreadMemberWidget::validateFormElement in Private Message 8
Same name and namespace in other branches
- 8.2 src/Plugin/Field/FieldWidget/PrivateMessageThreadMemberWidget.php \Drupal\private_message\Plugin\Field\FieldWidget\PrivateMessageThreadMemberWidget::validateFormElement()
Validates the form element for number of users.
Validates the form element to ensure that no more than the maximum number of allowed users has been entered. This is because the field itself is created as an unlimited cardinality field, but the widget allows for setting a maximum number of users.
File
- src/
Plugin/ Field/ FieldWidget/ PrivateMessageThreadMemberWidget.php, line 203
Class
- PrivateMessageThreadMemberWidget
- Defines the private message thread member widget.
Namespace
Drupal\private_message\Plugin\Field\FieldWidgetCode
public static function validateFormElement(array $element, FormStateInterface $form_state) {
$input_exists = FALSE;
$parents = $element['#parents'];
array_pop($parents);
$value = NestedArray::getValue($form_state
->getValues(), $parents, $input_exists);
unset($value['add_more']);
if (count($value) > $element['#max_members']) {
$form_state
->setError($element, t('Private messages threads cannot have more than @count members', [
'@count' => $element['#max_members'],
]));
}
}