(REF) APIv4 FieldSpec - Extract BasicSpecTrait (name, title, description)
authorTim Otten <totten@civicrm.org>
Fri, 16 Jul 2021 06:08:53 +0000 (23:08 -0700)
committerTim Otten <totten@civicrm.org>
Fri, 16 Jul 2021 06:38:24 +0000 (23:38 -0700)
Civi/Api4/Service/Spec/FieldSpec.php
Civi/Schema/Traits/BasicSpecTrait.php [new file with mode: 0644]

index f5733bac8a07e1b721dbb74b24113252177f099e..47ec136f7e5b56f94b4346ac7a8d553aedee74a7 100644 (file)
 
 namespace Civi\Api4\Service\Spec;
 
+use Civi\Schema\Traits\BasicSpecTrait;
+
 class FieldSpec {
+
+  // BasicSpecTrait: name, title, description
+  use BasicSpecTrait;
+
+
   /**
    * @var mixed
    */
   public $defaultValue;
 
-  /**
-   * @var string
-   */
-  public $name;
-
   /**
    * @var string
    */
   public $label;
 
-  /**
-   * @var string
-   */
-  public $title;
-
   /**
    * @var string
    */
@@ -43,11 +40,6 @@ class FieldSpec {
    */
   public $entity;
 
-  /**
-   * @var string
-   */
-  public $description;
-
   /**
    * @var bool
    */
@@ -184,24 +176,6 @@ class FieldSpec {
     return $this;
   }
 
-  /**
-   * @return string
-   */
-  public function getName() {
-    return $this->name;
-  }
-
-  /**
-   * @param string $name
-   *
-   * @return $this
-   */
-  public function setName($name) {
-    $this->name = $name;
-
-    return $this;
-  }
-
   /**
    * @return string
    */
@@ -220,24 +194,6 @@ class FieldSpec {
     return $this;
   }
 
-  /**
-   * @return string
-   */
-  public function getTitle() {
-    return $this->title;
-  }
-
-  /**
-   * @param string $title
-   *
-   * @return $this
-   */
-  public function setTitle($title) {
-    $this->title = $title;
-
-    return $this;
-  }
-
   /**
    * @param string $entity
    *
@@ -256,24 +212,6 @@ class FieldSpec {
     return $this->entity;
   }
 
-  /**
-   * @return string
-   */
-  public function getDescription() {
-    return $this->description;
-  }
-
-  /**
-   * @param string $description
-   *
-   * @return $this
-   */
-  public function setDescription($description) {
-    $this->description = $description;
-
-    return $this;
-  }
-
   /**
    * @return bool
    */
diff --git a/Civi/Schema/Traits/BasicSpecTrait.php b/Civi/Schema/Traits/BasicSpecTrait.php
new file mode 100644 (file)
index 0000000..b7c9f0a
--- /dev/null
@@ -0,0 +1,102 @@
+<?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\Schema\Traits;
+
+/**
+ *
+ * @package CRM
+ * @copyright CiviCRM LLC https://civicrm.org/licensing
+ */
+trait BasicSpecTrait {
+
+  /**
+   * Symbolic name of the field.
+   *
+   * Ex: 'first_name'
+   *
+   * @var string
+   */
+  public $name;
+
+  /**
+   * Backend-facing label. Shown in API, exports, and other configuration
+   * systems.
+   *
+   * If this field is presented to an administrator (e.g. when configuring a
+   * screen or configuring process-automation), how the field be entitled?
+   *
+   * Ex: ts('First Name')
+   *
+   * @var string
+   */
+  public $title;
+
+  /**
+   * Explanation of the purpose of the field.
+   *
+   * @var string
+   */
+  public $description;
+
+  /**
+   * @return string
+   */
+  public function getName() {
+    return $this->name;
+  }
+
+  /**
+   * @param string $name
+   *
+   * @return $this
+   */
+  public function setName($name) {
+    $this->name = $name;
+
+    return $this;
+  }
+
+  /**
+   * @return string
+   */
+  public function getTitle() {
+    return $this->title;
+  }
+
+  /**
+   * @param string $title
+   *
+   * @return $this
+   */
+  public function setTitle($title) {
+    $this->title = $title;
+    return $this;
+  }
+
+  /**
+   * @return string
+   */
+  public function getDescription() {
+    return $this->description;
+  }
+
+  /**
+   * @param string $description
+   *
+   * @return $this
+   */
+  public function setDescription($description) {
+    $this->description = $description;
+    return $this;
+  }
+
+}