Completed
Push — master ( daaff8...44ccfa )
by Ingo
22:24 queued 11:43
created

PopoverField::setPlacement()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
cc 2
eloc 7
c 2
b 0
f 1
nc 2
nop 1
dl 0
loc 14
rs 9.4285
1
<?php
2
3
/**
4
 * Popup form action menu for "more options"
5
 *
6
 * Only works with react forms at the moment
7
 */
8
class PopoverField extends FieldGroup
9
{
10
	private static $cast = [
11
		'PopoverTitle' => 'HTMLText'
12
	];
13
14
	/**
15
	 * Use custom react component
16
	 *
17
	 * @var string
18
	 */
19
	protected $schemaComponent = 'PopoverField';
20
21
	/**
22
	 * Optional title on popup box
23
	 *
24
	 * @var string
25
	 */
26
	protected $popoverTitle = null;
27
28
	/**
29
	 * Placement of the popup box, relative to the element triggering it.
30
	 * Valid values: bottom, top, left, right.
31
	 *
32
	 * @var string
33
	 */
34
	protected $placement = 'bottom';
35
36
	/**
37
	 * Get popup title
38
	 *
39
	 * @return string
40
	 */
41
	public function getPopoverTitle()
42
	{
43
		return $this->popoverTitle;
44
	}
45
46
	/**
47
	 * Set popup title
48
	 *
49
	 * @param string $popoverTitle
50
	 * @return $this
51
	 */
52
	public function setPopoverTitle($popoverTitle)
53
	{
54
		$this->popoverTitle = $popoverTitle;
55
		return $this;
56
	}
57
58
	/**
59
	 * Get popup placement
60
	 *
61
	 * @return string
62
	 */
63
	public function getPlacement()
64
	{
65
		return $this->placement;
66
	}
67
68
	public function setPlacement($placement)
69
	{
70
		$valid = ['top', 'right', 'bottom', 'left'];
71
72
		if (!in_array($placement, $valid)) {
73
			throw new InvalidArgumentException(
74
				'Invalid placement value. Valid: top, left, bottom, right'
75
			);
76
		}
77
78
		$this->placement = $placement;
79
80
		return $this;
81
	}
82
83
	public function getSchemaDataDefaults()
84
	{
85
		$schema = parent::getSchemaDataDefaults();
86
87
		$schema['data']['popoverTitle'] = $this->getPopoverTitle();
88
		$schema['data']['placement'] = $this->getPlacement();
89
90
		return $schema;
91
	}
92
}
93