public function ParagraphsSetForm::validateForm in Paragraphs Sets 8.2
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/ ParagraphsSetForm.php, line 128
Class
- ParagraphsSetForm
- Form controller for paragraph set forms.
Namespace
Drupal\paragraphs_sets\FormCode
public function validateForm(array &$form, FormStateInterface $form_state) {
$paragraphs_set = $this->entity;
$icon_file = $form_state
->getValue([
'icon_file',
'0',
]);
// Set the file UUID to the paragraph configuration.
if (!empty($icon_file) && ($file = $this->entityTypeManager
->getStorage('file')
->load($icon_file))) {
$paragraphs_set
->set('icon_uuid', $file
->uuid());
}
else {
$paragraphs_set
->set('icon_uuid', NULL);
}
$paragraphs_config = $form_state
->getValue('paragraphs_config') ?: 'paragraphs:';
try {
$paragraphs = Yaml::decode($paragraphs_config);
$form_state
->set('paragraphs', empty($paragraphs['paragraphs']) ? [] : $paragraphs['paragraphs']);
} catch (InvalidDataTypeException $e) {
$form_state
->setErrorByName('paragraphs_config', $e
->getMessage());
}
$types_available = paragraphs_type_get_types();
foreach ($paragraphs['paragraphs'] as $paragraph_config) {
if (!isset($types_available[$paragraph_config['type']])) {
$form_state
->setErrorByName('paragraphs_config', $this
->t('Unknown paragraph bundle %type', [
'%type' => $paragraph_config['type'],
]));
}
}
parent::validateForm($form, $form_state);
}