Skip to content

Instantly share code, notes, and snippets.

@ZombiMorgan
Last active November 8, 2020 11:39
Show Gist options
  • Select an option

  • Save ZombiMorgan/fa5cfa32ddba7cb396d4f99e17ed28c0 to your computer and use it in GitHub Desktop.

Select an option

Save ZombiMorgan/fa5cfa32ddba7cb396d4f99e17ed28c0 to your computer and use it in GitHub Desktop.
validate
<?php
function projects_node_project_form_validate(&$form, FormStateInterface $form_state) {
// $project = $form_state->getFormObject()->getEntity();
$value = $form_state->getValue(['field_value', '0', 'value']);
$sum = 0;
// $status = $form_state->getValue(['field_status', '0', 'value']);
foreach ($form_state->getValue('field_investors') as $index => $item)
if (is_numeric($index)) {
$sum += $item['subform']['field_contribution']['0']['value'] + $item['subform']['field_contribution_over']['0']['value'];
}
if ($value != $sum)
$form_state->setErrorByName('field_value', 'Проверьте сумму, должна быть: ' . $sum);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment