Completed
Push — master ( e04a88...42a5e8 )
by Craig
07:17
created

XsltBlock::getFormOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the Zikula package.
5
 *
6
 * Copyright Zikula Foundation - http://zikula.org/
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Zikula\BlocksModule\Block;
13
14
use DOMDocument;
15
use XSLTProcessor;
16
use Zikula\BlocksModule\AbstractBlockHandler;
17
18
/**
19
 * Block to display a parsed xml document
20
 */
21
class XsltBlock extends AbstractBlockHandler
22
{
23
    public function display(array $properties)
24
    {
25
        if (!$this->hasPermission('xsltblock::', "$properties[title]::", ACCESS_OVERVIEW)) {
26
            return '';
27
        }
28
29
        $doc = new DOMDocument();
30
        $xsl = new XSLTProcessor();
31
32
        // load stylesheet
33 View Code Duplication
        if (isset($properties['styleurl']) && !empty($properties['styleurl'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
34
            $doc->load($properties['styleurl']);
35
        } else {
36
            $doc->loadXML($properties['stylecontents']);
37
        }
38
        $xsl->importStyleSheet($doc);
39
40
        // load xml source
41 View Code Duplication
        if (isset($properties['docurl']) && !empty($properties['docurl'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
42
            $doc->load($properties['docurl']);
43
        } else {
44
            $doc->loadXML($properties['doccontents']);
45
        }
46
47
        // apply stylesheet and return output
48
        return $xsl->transformToXML($doc);
49
    }
50
51
    public function getFormClassName()
52
    {
53
        return 'Zikula\BlocksModule\Block\Form\Type\XsltBlockType';
54
    }
55
56
    public function getFormTemplate()
57
    {
58
        return '@ZikulaBlocksModule/Block/xslt_modify.html.twig';
59
    }
60
61
    public function getFormOptions()
62
    {
63
        return [
64
            'translator' => $this->getTranslator()
65
        ];
66
    }
67
}
68