-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Apply custom validation rules to REST API node creation (#2521)
- Loading branch information
Showing
5 changed files
with
108 additions
and
11 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
modules/dkan/dkan_dataset/modules/dkan_dataset_rest_api/dkan_dataset_rest_api.api.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Hooks provided by the DKAN Dataset REST API module. | ||
*/ | ||
|
||
/** | ||
* @addtogroup hooks | ||
* @{ | ||
*/ | ||
|
||
/** | ||
* Alter the list of validation handlers applied to all fields submited via API. | ||
* | ||
* @param $handlers | ||
* Array of validation handler functions to call. Handlers should be functions | ||
* that accept arguments: | ||
* * $node - the node object being validated, not yet saved. Passed as | ||
* reference. | ||
* * $field_name - the field name being validated. | ||
* * $info - the info array for the field. | ||
* | ||
*/ | ||
function hook_dkan_dataset_rest_api_field_validate_alter(&$handlers) { | ||
$handlers[] = 'mymodule_dkan_dataset_rest_api_validation_handler'; | ||
} | ||
|
||
/** | ||
* @} End of "addtogroup hooks". | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
name = DKAN Dataset test module | ||
description = Functionality to assist DKAN Dataset testing. | ||
core = 7.x | ||
dependencies[] = dkan_dataset | ||
dependencies[] = dkan_dataset_rest_api | ||
hidden = TRUE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Test module for DKAN Dataset and child modules. | ||
*/ | ||
|
||
function dkan_dataset_test_dkan_dataset_rest_api_field_validate_alter(&$handlers) { | ||
$handlers[] = 'dkan_dataset_test_validation_handler'; | ||
} | ||
|
||
function dkan_dataset_test_validation_handler(&$node, $field_name, $info) { | ||
if ($field_name == "body" && $node->body['und'][0]['value'] == "PHPUNIT Test Dataset Custom Validation") { | ||
throw new Exception("Test validation rejection"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters