Passed
Push — master ( 5a8560...7d651d )
by Bruno
05:41
created

Renderable_choice::viewable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Formularium\Frontend\Bulma\Renderable;
4
5
use Formularium\Datatype\Datatype_choice;
6
use Formularium\Field;
7
use Formularium\Frontend\Bulma\RenderableBulmaTrait;
8
use Formularium\Frontend\HTML\Renderable\Renderable_choice as HTMLRenderable_choice;
9
use Formularium\HTMLElement;
10
11
class Renderable_choice extends \Formularium\Renderable
12
{
13
    use RenderableBulmaTrait;
14
    
15
    public function viewable($value, Field $field, HTMLElement $previous): HTMLElement
16
    {
17
        return $previous;
18
    }
19
20
    /**
21
     * Subcall of wrapper editable() from RenderableMaterializeTrait
22
     *
23
     * @param mixed $value
24
     * @param Field $field
25
     * @param HTMLElement $previous
26
     * @return HTMLElement
27
     */
28
    public function _editable($value, Field $field, HTMLElement $previous): HTMLElement
0 ignored issues
show
Unused Code introduced by
The parameter $value is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

28
    public function _editable(/** @scrutinizer ignore-unused */ $value, Field $field, HTMLElement $previous): HTMLElement

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
29
    {
30
        $format = $field->getExtension(HTMLRenderable_choice::FORMAT_CHOOSER, HTMLRenderable_choice::FORMAT_CHOOSER_SELECT);
31
        
32
        if ($format == HTMLRenderable_choice::FORMAT_CHOOSER_RADIO) {
33
            $labels = [];
34
            // add extra classes
35
            foreach ($previous->get('.formularium-radio-item') as $container) {
36
                $label = $container->get('label')[0];
37
                $input = $container->get('input')[0];
38
                $labels[] = $label->prependContent($input)->addAttribute('class', 'radio');
39
            }
40
            $previous->get('.formularium-radio-group')[0]->setContent($labels);
41
        } else {
42
            // create a div around the old select
43
            $oldSelect = $previous->get('select')[0];
44
            $newSelect = clone $oldSelect;
45
            $oldSelect->setTag('div')->setAttribute('class', 'select')->setContent($newSelect);
46
        }
47
48
        foreach ($previous->getContent() as $e) {
49
            if ($e->getAttribute('class') === ['formularium-comment']) {
50
                $e->setTag('p')->setAttributes([
51
                    'class' => 'help',
52
                ]);
53
            }
54
        }
55
56
        return $previous;
57
    }
58
}
59