Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More granular field validation for datasets and resources. #2588

Merged
merged 1 commit into from
Jul 6, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,13 @@ function _dkan_dataset_rest_api_validate_fields($node) {
$instances = field_info_instances('node', $node->type);

foreach ($instances as $field_name => $info) {
$handlers = array('dkan_dataset_rest_api_validate_field');
$handlers = array(
'dkan_dataset_rest_api_validate_field_required',
'dkan_dataset_rest_api_validate_field_options',
);

drupal_alter('dkan_dataset_rest_api_field_validate', $handlers);

foreach($handlers as $function) {
$function($node, $field_name, $info);
}
Expand All @@ -166,13 +171,18 @@ function _dkan_dataset_rest_api_validate_fields($node) {
}

/**
* Default validation handler for Dataset REST API
* Default validation handler for Dataset REST API.
*/

function dkan_dataset_rest_api_validate_field(&$node, $field_name, $info) {
function dkan_dataset_rest_api_validate_field_required(&$node, $field_name, $info) {
if ($info['required'] == 1 && empty($node->{$field_name})) {
throw new Exception("Field {$field_name} is required");
}
}

/**
* Default validation handler for Dataset REST API.
*/
function dkan_dataset_rest_api_validate_field_options(&$node, $field_name, $info) {
if (!empty($node->{$field_name})) {
$options = _dkan_dataset_rest_api_field_validation_get_options($node, $field_name, $info);

Expand Down