Source of file SplitButton.php
Size: 3,563 Bytes - Last Modified: 2021-12-24T06:47:15+00:00
/var/www/docs.ssmods.com/process/src/code/SplitButton.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 | <?php /** * Simple extension of {@link TabSet} for displaying a split button. This is * based off the action-menu logic used by SilverStripe for the _More options_ * link on the SiteTree edit window. * * @author Firebrand <hello@firebrand.nz> * @license MIT * @package silverstripe-excel-export */ class SplitButton extends TabSet { /** * Underlying container to witch the buttons are goign to be added. * @var Tab */ protected $tab; /** * Create a new instance of SplitButton * @param string $name Form field name * @param string $title Title that will be displayed on the split button. * if not provided, the title will be guess from the `$name`. */ public function __construct($name, $title=null) { $args = func_get_args(); $name = array_shift($args); if ($args) { $title = array_shift($args); } // Guess the title if none provided if (!$title) { $title = self::name_to_label($name); } // Instanciate our undelying tab container $this->tab = new Tab( 'SplitButtonTab', $title ); //Call the parent consturctor parent::__construct($name, $this->tab); // Add the same class as the _more options_ link so we can piggy back // off that logic. $this->addExtraClass('ss-ui-action-tabset action-menus ss-ui-button'); // Add any provided button. if ($args) { foreach ($args as $button) { // Make sure we only add Form Fields to our tab. $isValidArg = (is_object($button) && !($button instanceof FormField)); if (!$isValidArg) { user_error( 'SplitButton::__construct(): Parameter not a valid FormField instance', E_USER_ERROR ); } $this->tab->push($button); } } // Define a custom spread sheet so we can style our button. Requirements::css(EXCELEXPORT_DIR . '/css/splitbutton.css'); } /** * @inheritdoc */ public function fieldByName($name) { return $this->tab->fieldByName(); } /** * @inheritdoc */ public function fieldPosition($field) { return $this->tab->fieldPosition($field); } /** * @inheritdoc */ public function getChildren() { return $this->tab->getChildren(); } /** * @inheritdoc */ public function setChildren($children) { return $this->tab->setChildren($children); } /** * @inheritdoc */ public function push(FormField $field) { return $this->tab->push($field); } /** * @inheritdoc */ public function insertBefore($field, $insertBefore) { return $this->tab->insertBefore($field, $insertBefore); } /** * @inheritdoc */ public function insertAfter($field, $insertBefore) { return $this->tab->insertAfter($field, $insertBefore); } /** * @inheritdoc */ public function removeByName($fieldName, $dataFieldOnly = false) { return $this->tab->removeByName($fieldName, $dataFieldOnly = false); } /** * @inheritdoc */ public function replaceField($fieldName, $newField) { return $this->tab->replaceField($fieldName, $newField); } } |