Merge pull request #14734 from yashodha/dev-1104
[civicrm-core.git] / Civi / API / Subscriber / APIv3SchemaAdapter.php
index 649ec9c7ccf530422194225f9c6fe6eafd1bcaca..3831cdf4d8b9a8af98c0d19d5473c9e2b794a9a9 100644 (file)
@@ -35,16 +35,17 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  * and validates that the fields are provided correctly.
  */
 class APIv3SchemaAdapter implements EventSubscriberInterface {
+
   /**
    * @return array
    */
   public static function getSubscribedEvents() {
-    return array(
-      Events::PREPARE => array(
-        array('onApiPrepare', Events::W_MIDDLE),
-        array('onApiPrepare_validate', Events::W_LATE),
-      ),
-    );
+    return [
+      Events::PREPARE => [
+        ['onApiPrepare', Events::W_MIDDLE],
+        ['onApiPrepare_validate', Events::W_LATE],
+      ],
+    ];
   }
 
   /**
@@ -81,6 +82,9 @@ class APIv3SchemaAdapter implements EventSubscriberInterface {
    */
   public function onApiPrepare_validate(\Civi\API\Event\Event $event) {
     $apiRequest = $event->getApiRequest();
+    if ($apiRequest['version'] > 3) {
+      return;
+    }
     // Not sure why this is omitted for generic actions. It would make sense
     // to omit 'getfields', but that's only one generic action.
 
@@ -96,7 +100,7 @@ class APIv3SchemaAdapter implements EventSubscriberInterface {
    * @return array
    */
   public function getDefaults($fields) {
-    $defaults = array();
+    $defaults = [];
 
     foreach ($fields as $field => $values) {
       if (isset($values['api.default'])) {
@@ -112,7 +116,7 @@ class APIv3SchemaAdapter implements EventSubscriberInterface {
    * @return array
    */
   public function getRequired($fields) {
-    $required = array('version');
+    $required = ['version'];
 
     foreach ($fields as $field => $values) {
       if (!empty($values['api.required'])) {