silverstripe-framework/forms/PopoverField.php

87 lines
1.3 KiB
PHP

<?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;
/**
* Placement of the popup box
*
* @var string
*/
protected $placement = 'bottom';
/**
* 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;
}
/**
* Get popup placement
*
* @return string
*/
public function getPlacement()
{
return $this->placement;
}
public function setPlacement($placement)
{
$valid = ['top', 'right', 'bottom', 'left'];
if (in_array($placement, $valid)) {
$this->placement = $placement;
}
return $this;
}
public function getSchemaDataDefaults()
{
$schema = parent::getSchemaDataDefaults();
$schema['data']['popoverTitle'] = $this->getPopoverTitle();
$schema['data']['placement'] = $this->getPlacement();
return $schema;
}
}