Completed
Push — master ( ffc46f...f233a4 )
by
unknown
20s queued 13s
created

OrderCustomReferenceWidget   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 9
Bugs 0 Features 0
Metric Value
wmc 5
eloc 14
c 9
b 0
f 0
dl 0
loc 58
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A addQuoteParameter() 0 3 1
A getName() 0 3 1
A getTemplate() 0 3 1
A addOrderCustomReferenceFormParameter() 0 10 1
A __construct() 0 4 1
1
<?php
2
3
/**
4
 * Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
5
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6
 */
7
8
namespace SprykerShop\Yves\OrderCustomReferenceWidget\Widget;
9
10
use Generated\Shared\Transfer\QuoteTransfer;
11
use Spryker\Yves\Kernel\Widget\AbstractWidget;
12
use SprykerShop\Yves\OrderCustomReferenceWidget\Form\OrderCustomReferenceForm;
13
14
/**
15
 * @method \SprykerShop\Yves\OrderCustomReferenceWidget\OrderCustomReferenceWidgetFactory getFactory()
16
 */
17
class OrderCustomReferenceWidget extends AbstractWidget
18
{
19
    protected const PARAMETER_QUOTE = 'quote';
20
21
    protected const FORM_ORDER_CUSTOM_REFERENCE = 'orderCustomReferenceForm';
22
23
    /**
24
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
25
     * @param string $backUrl
26
     */
27
    public function __construct(QuoteTransfer $quoteTransfer, string $backUrl)
28
    {
29
        $this->addQuoteParameter($quoteTransfer);
30
        $this->addOrderCustomReferenceFormParameter($quoteTransfer, $backUrl);
31
    }
32
33
    /**
34
     * @return string
35
     */
36
    public static function getName(): string
37
    {
38
        return 'OrderCustomReferenceWidget';
39
    }
40
41
    /**
42
     * @return string
43
     */
44
    public static function getTemplate(): string
45
    {
46
        return '@OrderCustomReferenceWidget/views/order-custom-reference/order-custom-reference.twig';
47
    }
48
49
    /**
50
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
51
     *
52
     * @return void
53
     */
54
    protected function addQuoteParameter(QuoteTransfer $quoteTransfer): void
55
    {
56
        $this->addParameter(static::PARAMETER_QUOTE, $quoteTransfer);
57
    }
58
59
    /**
60
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
61
     * @param string $backUrl
62
     *
63
     * @return void
64
     */
65
    protected function addOrderCustomReferenceFormParameter(QuoteTransfer $quoteTransfer, string $backUrl): void
66
    {
67
        $this->addParameter(
68
            static::FORM_ORDER_CUSTOM_REFERENCE,
69
            $this->getFactory()->getOrderCustomReferenceForm(
70
                [
71
                    OrderCustomReferenceForm::FIELD_ORDER_CUSTOM_REFERENCE => $quoteTransfer->getOrderCustomReference(),
72
                    OrderCustomReferenceForm::FIELD_BACK_URL => $backUrl,
73
                ]
74
            )->createView()
75
        );
76
    }
77
}
78