Fix Import Template path to be dynamic, depending on the entity
authorEileen McNaughton <emcnaughton@wikimedia.org>
Tue, 25 Jul 2023 04:18:51 +0000 (16:18 +1200)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Tue, 25 Jul 2023 04:20:56 +0000 (16:20 +1200)
Civi/Api4/Service/Spec/Provider/UserJobSpecProvider.php [new file with mode: 0644]
Civi/Api4/Utils/FormattingUtil.php
ext/civiimport/Managed/UserJobSearches.mgd.php

diff --git a/Civi/Api4/Service/Spec/Provider/UserJobSpecProvider.php b/Civi/Api4/Service/Spec/Provider/UserJobSpecProvider.php
new file mode 100644 (file)
index 0000000..e15274f
--- /dev/null
@@ -0,0 +1,39 @@
+<?php
+
+/*
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC. All rights reserved.                        |
+ |                                                                    |
+ | This work is published under the GNU AGPLv3 license with some      |
+ | permitted exceptions and without any warranty. For full license    |
+ | and copyright information, see https://civicrm.org/licensing       |
+ +--------------------------------------------------------------------+
+ */
+
+namespace Civi\Api4\Service\Spec\Provider;
+
+use Civi\Api4\Service\Spec\RequestSpec;
+use Civi\Core\Service\AutoService;
+
+/**
+ * @service
+ * @internal
+ */
+class UserJobSpecProvider extends AutoService implements Generic\SpecProviderInterface {
+
+  /**
+   * @inheritDoc
+   */
+  public function modifySpec(RequestSpec $spec): void {
+    $spec->getFieldByName('job_type')
+      ->setSuffixes(['name', 'label', 'url']);
+  }
+
+  /**
+   * @inheritDoc
+   */
+  public function applies($entity, $action): bool {
+    return $entity === 'UserJob';
+  }
+
+}
index 380a7afc946a9b6db10d9960c03efda606d6c7b8..9498079c3fce8960ddb5ea291369afca675cfd5a 100644 (file)
@@ -30,7 +30,7 @@ class FormattingUtil {
   /**
    * @var string[]
    */
-  public static $pseudoConstantSuffixes = ['name', 'abbr', 'label', 'color', 'description', 'icon', 'grouping'];
+  public static $pseudoConstantSuffixes = ['name', 'abbr', 'label', 'color', 'description', 'icon', 'grouping', 'url'];
 
   /**
    * Massage values into the format the BAO expects for a write operation
index bf676b082cbfa1848360a47aadb5eaf7d7c19910..22747d494e0ae026f3e2bfe4f4ab084bb22b601f 100644 (file)
@@ -138,7 +138,7 @@ return [
               'label' => E::ts('Import Name'),
               'sortable' => TRUE,
               'link' => [
-                'path' => 'civicrm/import/contribution?reset=1&template_id=[id]',
+                'path' => '[job_type:url]?reset=1&template_id=[id]',
                 'entity' => '',
                 'action' => '',
                 'join' => '',
@@ -264,7 +264,7 @@ return [
               'label' => E::ts('Import Name'),
               'sortable' => TRUE,
               'link' => [
-                'path' => 'civicrm/import/contribution?reset=1&template_id=[id]',
+                'path' => '[job_type:url]?reset=1&template_id=[id]',
                 'entity' => '',
                 'action' => '',
                 'join' => '',