Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 26
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
BoardDescriptionWidget
0.00% covered (danger)
0.00%
0 / 26
0.00% covered (danger)
0.00%
0 / 2
30
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 22
0.00% covered (danger)
0.00%
0 / 1
20
 wrapInDiv
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace Flow\OOUI;
4
5class BoardDescriptionWidget extends \OOUI\Widget {
6
7    /** @var \OOUI\ButtonWidget */
8    protected $editButton;
9
10    /** @var string */
11    protected $description = '';
12
13    /**
14     * @var \OOUI\Tag
15     */
16    private $contentWrapper;
17
18    public function __construct( array $config = [] ) {
19        parent::__construct( $config );
20
21        if ( isset( $config['description'] ) ) {
22            $this->description = $config['description'];
23        }
24        $editLink = null;
25        if ( isset( $config['editLink'] ) ) {
26            $editLink = $config['editLink'];
27        }
28
29        $this->editButton = new \OOUI\ButtonWidget( [
30            'framed' => false,
31            'href' => $editLink,
32            'label' => wfMessage( 'flow-edit-header-link' )->text(),
33            'icon' => 'edit',
34            'flags' => 'progressive',
35            'classes' => [ 'flow-ui-boardDescriptionWidget-editButton' ]
36        ] );
37
38        // Content
39        $this->contentWrapper = $this->wrapInDiv(
40            $this->description,
41            [ 'flow-ui-boardDescriptionWidget-content', 'mw-parser-output' ]
42        );
43
44        // Initialize
45        $this->addClasses( [ 'flow-ui-boardDescriptionWidget', 'flow-ui-boardDescriptionWidget-nojs' ] );
46
47        if ( $editLink ) {
48            $this->appendContent( $this->wrapInDiv( (string)$this->editButton ) );
49        }
50        $this->appendContent( $this->contentWrapper );
51    }
52
53    /**
54     * Wrap some content in a div
55     *
56     * @param string $content Content to wrap
57     * @param string[] $classes Classes to add to the div
58     * @return \OOUI\Tag New div with content
59     */
60    private function wrapInDiv( $content, array $classes = [] ) {
61        $tag = new \OOUI\Tag( 'div' );
62        $tag->addClasses( $classes );
63        $tag->appendContent( new \OOUI\HtmlSnippet( $content ) );
64
65        return $tag;
66    }
67}