protected function addButtonToForm($buttonType, $form, $actions = true)
 {
     if (substr($buttonType, 0, 6) == "Group_") {
         $groupName = substr($buttonType, 6);
         $groupConfig = Config::inst()->get("BetterButtonsGroups", $groupName);
         $label = isset($groupConfig['label']) ? $groupConfig['label'] : $groupName;
         $buttons = isset($groupConfig['buttons']) ? $groupConfig['buttons'] : array();
         $button = DropdownFormAction::create(_t('GridFieldBetterButtons.' . $groupName, $label));
         foreach ($buttons as $b => $bool) {
             $b = "UncleCheese\\BetterButtons\\Buttons\\" . $b;
             if ($bool && class_exists($b)) {
                 $buttonObj = Injector::inst()->create($b, $form, $this->owner);
                 if ($buttonObj->hasMethod('shouldDisplay') && !$buttonObj->shouldDisplay()) {
                     continue;
                 }
                 if ($buttonObj instanceof UncleCheese\BetterButtons\Buttons\Button) {
                     if ($buttonObj instanceof Button_Versioned && !$this->checkVersioned()) {
                         continue;
                     }
                     $buttonObj->transformToInput();
                 }
                 $button->push($buttonObj);
             } else {
                 throw new Exception("The button type {$b} doesn't exist.");
             }
         }
         if ($actions) {
             $form->Actions()->push($button);
         } else {
             $this->utils[$button->class] = $button;
         }
     } elseif (class_exists("UncleCheese\\BetterButtons\\Buttons\\" . $buttonType)) {
         $button = Injector::inst()->create("UncleCheese\\BetterButtons\\Buttons\\" . $buttonType, $form, $this->owner);
         if ($button->hasMethod('shouldDisplay') && !$button->shouldDisplay()) {
             return;
         }
         if ($button instanceof UncleCheese\BetterButtons\Buttons\Button) {
             if ($button instanceof Button_Versioned && !$this->checkVersioned()) {
                 return;
             }
             $button->transformToButton();
         }
         if ($actions) {
             $form->Actions()->push($button);
         } else {
             $this->utils[$button->class] = $button;
         }
     } else {
         throw new Exception("The button type {$buttonType} doesn't exist.");
     }
 }
Пример #2
0
 /**
  * Creates a button group {@link DropdownFormAction}
  * @param  string                           $groupName The name of the group
  * @return DropdownFormAction
  */
 protected function createButtonGroup($groupName)
 {
     $groupConfig = Config::inst()->get("BetterButtonsGroups", $groupName);
     $label = isset($groupConfig['label']) ? $groupConfig['label'] : $groupName;
     $buttons = isset($groupConfig['buttons']) ? $groupConfig['buttons'] : array();
     $button = DropdownFormAction::create(_t('GridFieldBetterButtons.' . $groupName, $label));
     foreach ($buttons as $b => $bool) {
         if ($bool) {
             if ($child = $this->instantiateButton($b)) {
                 $button->push($child);
             }
         }
     }
     return $button;
 }