Completed
Push — master ( 6623e1...0a591e )
by Fabien
03:37
created

RelationEditRenderer::render()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 9
rs 9.6666
cc 2
eloc 5
nc 2
nop 0
1
<?php
2
namespace Fab\Vidi\Grid;
3
4
/**
5
 * This file is part of the TYPO3 CMS project.
6
 *
7
 * It is free software; you can redistribute it and/or modify it under
8
 * the terms of the GNU General Public License, either version 2
9
 * of the License, or any later version.
10
 *
11
 * For the full copyright and license information, please read the
12
 * LICENSE.txt file that was distributed with this source code.
13
 *
14
 * The TYPO3 project - inspiring people to share!
15
 */
16
17
use Fab\Vidi\Tca\Tca;
18
use TYPO3\CMS\Core\Imaging\Icon;
19
20
/**
21
 * Class for editing mm relation between objects.
22
 */
23
class RelationEditRenderer extends ColumnRendererAbstract
24
{
25
26
    /**
27
     * @return string
28
     */
29
    public function render()
30
    {
31
        $output = '';
32
        if ($this->isBackendMode()) {
33
            $output = $this->renderForBackend();
34
        }
35
36
        return $output;
37
    }
38
39
    /**
40
     * @return string
41
     */
42
    protected function renderForBackend()
43
    {
44
45
        // Initialize url parameters array.
46
        $urlParameters = array(
47
            $this->getModuleLoader()->getParameterPrefix() => array(
48
                'controller' => 'Content',
49
                'action' => 'edit',
50
                'matches' => array('uid' => $this->object->getUid()),
51
                'fieldNameAndPath' => $this->getFieldName(),
52
            ),
53
        );
54
55
        $fieldLabel = Tca::table()->field($this->getFieldName())->getLabel();
56
        if ($fieldLabel) {
57
            $fieldLabel = str_replace(':', '', $fieldLabel); // sanitize label
58
        }
59
60
        return sprintf(
61
            '<div style="text-align: right" class="pull-right invisible"><a href="%s" class="btn-edit-relation" data-field-label="%s">%s</a></div>',
62
            $this->getModuleLoader()->getModuleUrl($urlParameters),
63
            $fieldLabel,
64
            $this->getIconFactory()->getIcon('actions-edit-add', Icon::SIZE_SMALL)
65
        );
66
    }
67
68
    /**
69
     * Returns whether the current mode is Frontend
70
     *
71
     * @return bool
72
     */
73
    protected function isBackendMode()
74
    {
75
        return TYPO3_MODE === 'BE';
76
    }
77
78
}
79