php/mixins/GroupElement.php
public function addItems( array $items, $index = null ) {
		foreach ( $items as $item ) {
			// Check if item exists then remove it first, effectively "moving" it
			$currentIndex = array_search( $item, $this->items, true );
			if ( $currentIndex !== false ) {
				$this->removeItems( [ $item ] );
				// Adjust index to compensate for removal
				if ( $currentIndex < $index ) {
					$index--;
				}
			}
			// Add the item
			$item->setElementGroup( $this );
		}

		if ( $index === null || $index < 0 || $index >= count( $this->items ) ) {
			$this->items = array_merge( $this->items, $items );
		} else {
			array_splice( $this->items, $index, 0, $items );
		}

		// Update actual target element contents to reflect our list
		$this->group->clearContent();
		$this->group->appendContent( $this->items );

		return $this;
	}
public function addItems( array $items, $index = null ) {
		foreach ( $items as $item ) {
			// Check if item exists then remove it first, effectively "moving" it
			$currentIndex = array_search( $item, $this->items, true );
			if ( $currentIndex !== false ) {
				$this->removeItems( [ $item ] );
				// Adjust index to compensate for removal
				if ( $currentIndex < $index ) {
					$index--;
				}
			}
			// Add the item
			$item->setElementGroup( $this );
		}

		if ( $index === null || $index < 0 || $index >= count( $this->items ) ) {
			$this->items = array_merge( $this->items, $items );
		} else {
			array_splice( $this->items, $index, 0, $items );
		}

		// Update actual target element contents to reflect our list
		$this->group->clearContent();
		$this->group->appendContent( $this->items );

		return $this;
	}
public function addItems ( array $ items , $ index = null ) { foreach ( $ items as $ item ) { // Check if item exists then remove it first, effectively "moving" it $ currentIndex = array_search ( $ item , $ this -> items , true ) ; if ( $ currentIndex !== false ) { $ this -> removeItems ( [ $ item ] ) ; // Adjust index to compensate for removal if ( $ currentIndex < $ index ) { $ index -- ; } } // Add the item $ item -> setElementGroup ( $ this ) ; } if ( $ index === null || $ index < 0 || $ index >= count ( $ this -> items ) ) { $ this -> items = array_merge ( $ this -> items , $ items ) ; } else { array_splice ( $ this -> items , $ index , 0 , $ items ) ; } // Update actual target element contents to reflect our list $ this -> group -> clearContent ( ) ; $ this -> group -> appendContent ( $ this -> items ) ; return $ this ; }
Add items.

Adding an existing item will move it.

@param Element[] $items Items
@param int|null $index Index to insert items at
@return $this
Add items .