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

addOrderCustomReferenceFormParameter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 6
c 2
b 0
f 0
dl 0
loc 10
rs 10
cc 1
nc 1
nop 2
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