Mooeypoo has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/279059

Change subject: Allow appendContent to accept an array
......................................................................

Allow appendContent to accept an array

This is very useful when creating a dynamic group of items to append
to some element or tag, instead of having to call call_user_func_array
when these are needed.

See the usage in GroupElement.php#80 for example, as adapted for the
new usage in this commit.

Change-Id: I2903fddfae9e286922109fc5e653e0fe344912cf
---
M php/Tag.php
M php/mixins/GroupElement.php
2 files changed, 14 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/oojs/ui refs/changes/59/279059/1

diff --git a/php/Tag.php b/php/Tag.php
index 95fe115..a88d85a 100644
--- a/php/Tag.php
+++ b/php/Tag.php
@@ -167,7 +167,14 @@
        /**
         * Add content to the end.
         *
-        * Accepts variadic arguments (the $content argument can be repeated 
any number of times).
+        * Accepts either variadic arguments (the $content argument can be 
repeated any number of times)
+        * or an array of arguments.
+        *
+        * For example, these uses are valid:
+        * * $tag->appendContent( [ $element1, $element2 ] );
+        * * $tag->appendContent( $element1, $element2 );
+        * This, however, is not acceptable
+        * * $tag->appendContent( [ $element1, $element2 ], $element3 );
         *
         * @param string|Tag|HtmlSnippet $content Content to append. Strings 
will be HTML-escaped
         *   for output, use a HtmlSnippet instance to prevent that.
@@ -175,7 +182,11 @@
         */
        public function appendContent( /* $content... */ ) {
                $contents = func_get_args();
-               $this->content = array_merge( $this->content, $contents );
+               if ( is_array( $contents[ 0 ] ) ) {
+                       $this->content = array_merge( $this->content, 
$contents[ 0 ] );
+               } else {
+                       $this->content = array_merge( $this->content, $contents 
);
+               }
                return $this;
        }
 
diff --git a/php/mixins/GroupElement.php b/php/mixins/GroupElement.php
index 1409c0b..ddcfad0 100644
--- a/php/mixins/GroupElement.php
+++ b/php/mixins/GroupElement.php
@@ -77,7 +77,7 @@
 
                // Update actual target element contents to reflect our list
                $this->target->clearContent();
-               call_user_func_array( [ $this->target, 'appendContent' ], 
$this->items );
+               $this->target->appendContent( $this->items );
 
                return $this;
        }

-- 
To view, visit https://gerrit.wikimedia.org/r/279059
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2903fddfae9e286922109fc5e653e0fe344912cf
Gerrit-PatchSet: 1
Gerrit-Project: oojs/ui
Gerrit-Branch: master
Gerrit-Owner: Mooeypoo <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to