You are here

function filebrowser_node_validate in Filebrowser 8

File

./filebrowser.module, line 192
Validates file path input on node form

Code

function filebrowser_node_validate(\Drupal\Core\Entity\EntityInterface $node, $form, &$form_state) {

  // debug print_r($node); exit();
  if ($node
    ->bundle() == 'dir_listing') {

    // Validate file path
    $file_path = $node->field_file_path
      ->getValue()[0]['value'];
    $encoding = $node->field_encoding
      ->getValue()[0]['value'];

    // Validate the file path entered
    $result = _fb_validate_file_path($file_path, $encoding);
    if ($result) {
      \Drupal::formBuilder()
        ->setErrorByName('field_file_path', $form_state, $result);
    }
    else {
      drupal_set_message(t('The directory %dir has been created.', array(
        '%dir' => $file_path,
      )));
    }
  }
}