Merge pull request #18506 from totten/master-bundle-array
[civicrm-core.git] / CRM / Core / Resources / CollectionAdderTrait.php
index 469d1c426f880c35fcd6ce3247dd74d745164a70..da81a34a03d9935211646b66e49ace2441929fc6 100644 (file)
@@ -14,7 +14,9 @@
  *
  * This trait is a building-block for creating classes which maintain a list of
  * resources. It defines a set of helper functions which provide syntactic sugar
- * for calling the add() method.
+ * for calling the add() method. It implements most of the `CollectionAdderInterface`.
+ *
+ * @see CRM_Core_Resources_CollectionAdderInterface
  */
 trait CRM_Core_Resources_CollectionAdderTrait {
 
@@ -36,7 +38,28 @@ trait CRM_Core_Resources_CollectionAdderTrait {
    * @return array
    * @see CRM_Core_Resources_CollectionTrait::findCreateSettingSnippet()
    */
-  abstract protected function &findCreateSettingSnippet($options = []): array;
+  abstract public function &findCreateSettingSnippet($options = []): array;
+
+  /**
+   * Add an HTML blob.
+   *
+   * Ex: addMarkup('<p>Hello world!</p>', ['weight' => 123]);
+   *
+   * @param string $markup
+   *   HTML code.
+   * @param array $options
+   *   Open-ended list of key-value options. See CollectionInterface docs.
+   *   Positional equivalence: addMarkup(string $code, int $weight, string $region).
+   * @return static
+   * @see CRM_Core_Resources_CollectionInterface
+   * @see CRM_Core_Resources_CollectionAdderInterface::addMarkup()
+   */
+  public function addMarkup(string $markup, ...$options) {
+    $this->add(self::mergeStandardOptions($options, [
+      'markup' => $markup,
+    ]));
+    return $this;
+  }
 
   /**
    * Export permission data to the client to enable smarter GUIs.