Completed
Pull Request — master (#4369)
by Craig
05:32
created

TemplateBlock   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 10
c 1
b 0
f 1
dl 0
loc 20
rs 10
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A display() 0 13 6
A getFormClassName() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Zikula package.
7
 *
8
 * Copyright Zikula - https://ziku.la/
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Zikula\BlocksModule\Block;
15
16
use Zikula\BlocksModule\AbstractBlockHandler;
17
use Zikula\BlocksModule\Block\Form\Type\TemplateBlockType;
18
19
class TemplateBlock extends AbstractBlockHandler
20
{
21
    public function display(array $properties): string
22
    {
23
        $title = !empty($properties['title']) ? $properties['title'] : '';
24
        if ((!$this->hasPermission('Templateblock::', $title . '::', ACCESS_OVERVIEW))
25
        || (!$this->hasPermission('Templateblock::bid', '::' . $properties['bid'], ACCESS_OVERVIEW))) {
26
            return '';
27
        }
28
        $path = $properties['path'] ?? '';
29
        if (empty($path) || !$this->twig->getLoader()->exists($path)) {
30
            return '';
31
        }
32
33
        return $this->renderView($path);
34
    }
35
36
    public function getFormClassName(): string
37
    {
38
        return TemplateBlockType::class;
39
    }
40
}
41