Shortcut for quick making of lists

Note: 'list' is a reserved keyword ;-)

@param array $items
@param array $attributes
@param string $tag ul or ol
@return string
195671
public static function alist(array $items, array $attributes = null, $tag = 'ul') {
        $output = html_writer::start_tag($tag, $attributes)."\n";
        foreach ($items as $item) {
            $output .= html_writer::tag('li', $item)."\n";
        }
        $output .= html_writer::end_tag($tag);
        return $output;
    }
1082304
public static function createAttributes($attributes = [])
    {
        $list = [];

        foreach ($attributes as $key => $value)
        {
            $list[] = sprintf('%s="%s"', $key, is_array($value) ? implode(' ', $value) : $value);
        }

        return implode(' ', $list);
    }
179376
public static function renderHtmlTag(array $attributes, $htmlTag, $shortEndTag)
    {
        $output = '<'.$htmlTag;

        foreach ($attributes as $attr => $value) {
            if (static::isValidValue($value)) {
                $output .= ' '.$attr.'="'.$value.'"';
            }
        }

        $output .= $shortEndTag ? ' />' : '></'.$htmlTag.'>';

        return $output;
    }
1219527
public function buildTagAttributes(array $attributes)
	{
		$html = array();

		foreach ($attributes as $key => $value)
		{
			if (is_null($value))
				continue;

			if (is_numeric($key))
				$key = $value;

			$html[] = $key . '="' . htmlentities($value, ENT_QUOTES, 'UTF-8', false) . '"';
		}

		return (count($html) > 0) ? ' ' . implode(' ', $html) : '';
	}
426368
private function getNextItem(Tag $item, $items)
    {
        $currentItem = $items[0];

        while ($currentItem !== null and $currentItem !== $item) {
            $currentItem = next($items);
        }

        $next = next($items);

        return $next !== false ? $next : null;
    }
1202141
public static function indexableString(array $tags) {
        $tagstr = '';

        for ($i = 0; $i < func_num_args(); $i++) {
            $tags = func_get_arg($i);

            if (is_array($tags))
                foreach($tags as $tag)
                    $tagstr .= $tag->getTagSlug().' '.$tag->getTagRoleDisplay().' '.$tag->getTagValueDisplay().' '.$tag->getTagLinkTitle().' ';
        }

        return trim($tagstr);
    }
1266742
public function printTag( $tag, $value, array $attributes = [] )
	{
		$attributes = $this->buildAttributesFor( $tag, $attributes );

		printf( '<%s>%s</%s>',
			rtrim( sprintf( '%s %s', $tag, $attributes )),
			$value,
			$tag
		);
	}
956219
public static function ListItem( $content, $level = 0, $attributes = array() )
	{
		$depth	= 2 * abs( (int) $level ) + 1;
		$indent	= str_repeat( "  ", $depth );
		$tag	= UI_HTML_Tag::create( "li", $content, $attributes );
		$code	= $indent.$tag;
		return $code;
	}
583703
public static function createTag($tag, $attributes, $content = null)
    {
        $tag = strtolower($tag);

        // Build list of arguments
        $preparedAttributes = '';
        foreach ($attributes as $attributeKey => $attributeValue) {
            // Only set non-empty strings (ensures strlen(0) > 0)
            if (strlen($attributeValue) > 0) {
                $preparedAttributes .= sprintf(
                    ' %s="%s"',
                    $attributeKey,
                    Convert::raw2att($attributeValue)
                );
            }
        }

        // Check void element type
        if (in_array($tag, static::config()->get('void_elements'))) {
            if ($content) {
                throw new InvalidArgumentException("Void element \"{$tag}\" cannot have content");
            }
            return "<{$tag}{$preparedAttributes} />";
        }

        // Closed tag type
        return "<{$tag}{$preparedAttributes}>{$content}</{$tag}>";
    }
720786
public static function medias(array $items, $tag = 'div')
    {
        if (!empty($items)) {
            $output = '';
            foreach ($items as $itemOptions) {
                if (isset($itemOptions['visible']) && $itemOptions['visible'] === false) {
                    continue;
                }
                // todo: consider removing the support for htmlOptions.
                $options = TbArray::popValue('htmlOptions', $itemOptions, array());
                if (!empty($options)) {
                    $itemOptions = TbArray::merge($options, $itemOptions);
                }
                $image = TbArray::popValue('image', $itemOptions);
                $heading = TbArray::popValue('heading', $itemOptions, '');
                $content = TbArray::popValue('content', $itemOptions, '');
                TbArray::defaultValue('tag', $tag, $itemOptions);
                $output .= self::media($image, $heading, $content, $itemOptions);
            }
            return $output;
        }
        return '';
    }
89212
public function tag($tags)
    {
        return $this->proxy($this->parent, $this->storage, $this->storageName)
                    ->with($this->attributes(['tag' => $tags]));
    }
389023
public function tag($tag, array $keys)
	{
		foreach ($keys as $key)
		{
			$resolvedKey = $this->resolveAlias($key);

			if (!isset($this->tags[$tag]))
			{
				$this->tags[$tag] = array();
			}

			$this->tags[$tag][] = $resolvedKey;
		}

		// Prune duplicates
		$this->tags[$tag] = array_unique($this->tags[$tag]);

		return $this;
	}
1093739
public function openTag($name, $attributes=null) {
        if ($attributes) {
          $initial = $name;
          $name = self::open($initial);
          $name .= self::getAttributesCollection($attributes);
          $name .= ">";

          return $name;
        } 

      return self::fullOpen($name);
    }
1183405
private function formatHtmlAttribute($attributes = [])
    {
        $attrArr = [];
        foreach ($attributes as $name => $val) {
            $attrArr[] = "$name=\"$val\"";
        }

        return implode(' ', $attrArr);
    }
371431
public static function ul( $items, $options = [] ) {
		$tag         = ArrayHelper::remove( $options, 'tag', 'ul');
		$encode      = ArrayHelper::remove( $options, 'encode', FALSE );
		$formatter   = ArrayHelper::remove( $options, 'item');
		$separator   = ArrayHelper::remove( $options, 'separator', "\n");
		$itemOptions = ArrayHelper::remove( $options, 'itemOptions', []);
		$classFor    = ArrayHelper::remove( $itemOptions, 'class_for', null );

		if ( empty( $items ) ) {
			return static::tag( $tag, '', $options );
		}
		$results = [];
		foreach ( $items as $i => $item ) {
			if ( $formatter !== NULL ) {
				$results[] = call_user_func( $formatter, $item, $i );
			} else {
				$_itemOptions = $itemOptions;
				if ( isset( $classFor ) && array_key_exists( $i, $classFor ) ) {
					static::addCssClass( $_itemOptions, $classFor[ $i ] );
				}
				$results[] = static::tag('li', $encode ? static::encode( $item ) : $item, $_itemOptions );
			}
		}

		return static::tag( $tag, $separator . join( $separator, $results ) . $separator, $options );
	}
475303
protected function getFormattedTags(array $tags)
    {
        $add =array();

        foreach ($tags as $key => $value) {
            if (is_bool($value)) {
                $value = $value ? "true" : "false";
            }
            $add[] = "#$key:$value";
        }

        return !empty($add) ? '|'.implode(',', $add) : null;
    }
1330454
protected function handleTagOpenForArray( $parser, $tag, $attributes )
	{
		$count	= count( $this->last ) - 1;
		$this->last[$count][]	= array(
			"tag"			=> $tag,
			"attributes"	=> $attributes,
			"content"		=> '',
			"children"		=> array()
		);
		$index	= count( $this->last[$count] ) - 1;
		$this->last[]	= &$this->last[$count][$index]['children'];
	}