2016-07-07 00:39:44 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Popup form action menu for "more options"
|
|
|
|
*
|
|
|
|
* Only works with react forms at the moment
|
|
|
|
*/
|
|
|
|
class PopoverField extends FieldGroup
|
|
|
|
{
|
|
|
|
private static $cast = [
|
|
|
|
'PopoverTitle' => 'HTMLText'
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Use custom react component
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $schemaComponent = 'PopoverField';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Optional title on popup box
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $popoverTitle = null;
|
|
|
|
|
2016-08-12 06:34:51 +02:00
|
|
|
/**
|
2016-08-28 03:45:16 +02:00
|
|
|
* Placement of the popup box, relative to the element triggering it.
|
|
|
|
* Valid values: bottom, top, left, right.
|
2016-08-12 06:34:51 +02:00
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $placement = 'bottom';
|
|
|
|
|
2016-07-07 00:39:44 +02:00
|
|
|
/**
|
|
|
|
* Get popup title
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getPopoverTitle()
|
|
|
|
{
|
|
|
|
return $this->popoverTitle;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set popup title
|
|
|
|
*
|
|
|
|
* @param string $popoverTitle
|
|
|
|
* @return $this
|
|
|
|
*/
|
|
|
|
public function setPopoverTitle($popoverTitle)
|
|
|
|
{
|
|
|
|
$this->popoverTitle = $popoverTitle;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2016-08-12 06:34:51 +02:00
|
|
|
/**
|
|
|
|
* Get popup placement
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getPlacement()
|
|
|
|
{
|
|
|
|
return $this->placement;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setPlacement($placement)
|
|
|
|
{
|
|
|
|
$valid = ['top', 'right', 'bottom', 'left'];
|
|
|
|
|
2016-08-28 03:45:16 +02:00
|
|
|
if (!in_array($placement, $valid)) {
|
|
|
|
throw new InvalidArgumentException(
|
|
|
|
'Invalid placement value. Valid: top, left, bottom, right'
|
|
|
|
);
|
2016-08-12 06:34:51 +02:00
|
|
|
}
|
2016-08-28 03:45:16 +02:00
|
|
|
|
|
|
|
$this->placement = $placement;
|
|
|
|
|
2016-08-12 06:34:51 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2016-07-07 00:39:44 +02:00
|
|
|
public function getSchemaDataDefaults()
|
|
|
|
{
|
|
|
|
$schema = parent::getSchemaDataDefaults();
|
2016-08-12 06:34:51 +02:00
|
|
|
|
|
|
|
$schema['data']['popoverTitle'] = $this->getPopoverTitle();
|
|
|
|
$schema['data']['placement'] = $this->getPlacement();
|
|
|
|
|
2016-07-07 00:39:44 +02:00
|
|
|
return $schema;
|
|
|
|
}
|
|
|
|
}
|