11/05/2013 2:46pm

PHP | Problem - Grid Field Custom Action Buttons .. Working Example.


class Artist extends DataObject{


public static $db = array(
'IsPublished' => 'Boolean',
);


public function getCMSActions() {
$fields = parent::getCMSActions();

if($this->IsPublished){
$unPublishButton = FormAction::create('unpublish');
$unPublishButton->setTitle('Hide');
$unPublishButton->setDescription("UnPublish this artists");
$unPublishButton->addExtraClass('ss-ui-action-destructive');
$unPublishButton->setAttribute('data-icon', 'accept');
$fields->push($unPublishButton);
} else {
$publishButton = FormAction::create('publish');
$publishButton->setTitle('Publish');
$publishButton->setDescription("Publish this artists");
$publishButton->addExtraClass('ss-ui-action-constructive');
$publishButton->setAttribute('data-icon', 'accept');
$fields->push($publishButton);
}
return $fields;
}
}




<?php

class DataAdmin extends ModelAdmin {

static $managed_models = array(
'Artist'
);

static $url_segment = 'dataadmin';
static $menu_title = 'Site Admin';

function getEditForm($id = null, $fields = null) {
$form = parent::getEditForm($id , $fields);
$listfield = $form->Fields()->fieldByName($this->modelClass);

if($gridField = $listfield->getConfig()->getComponentByType('GridFieldDetailForm')) {
$gridField->setItemRequestClass('ArtistPublishFieldDetailForm_ItemRequest');
}

return $form;
}

}

class ArtistPublishFieldDetailForm extends GridFieldDetailForm {

}

class ArtistPublishFieldDetailForm_ItemRequest extends GridFieldDetailForm_ItemRequest {

function ItemEditForm() {
$form = parent::ItemEditForm();
$formActions = $form->Actions();
if($actions = $this->record->getCMSActions()) {
foreach($actions as $action) {
$formActions->push($action);
}
}
$form->setActions($formActions);
return $form;
}

function publish($data, $form) {
$controller = Controller::curr();

$this->record->IsPublished = 1 ;
$this->record->write();

$message = sprintf(
_t('Artist.Published', 'Published %s %s'),
$this->record->singular_name(),
'<a href="' . $this->Link('edit') . '">"' . htmlspecialchars($this->record->Title, ENT_QUOTES) . '"</a>'
);

$form->sessionMessage($message, 'good');

if($this->gridField->getList()->byId($this->record->ID)) {
return $this->edit(Controller::curr()->getRequest());
} else {
$noActionURL = $controller->removeAction($data['url']);
$controller->getRequest()->addHeader('X-Pjax', 'Content');
return $controller->redirect($noActionURL, 302);
}
}

function unpublish($data, $form) {
$controller = Controller::curr();

$this->record->IsPublished = 0 ;
$this->record->write();

$message = sprintf(
_t('Artist.unpublish', 'Unpublished %s %s'),
$this->record->singular_name(),
'<a href="' . $this->Link('edit') . '">"' . htmlspecialchars($this->record->Title, ENT_QUOTES) . '"</a>'
);

$form->sessionMessage($message, 'bad');

if($this->gridField->getList()->byId($this->record->ID)) {
return $this->edit(Controller::curr()->getRequest());
} else {
$noActionURL = $controller->removeAction($data['url']);
$controller->getRequest()->addHeader('X-Pjax', 'Content');
return $controller->redirect($noActionURL, 302);
}
}

}



4 Comments 4 Solutions

22/08/2014 3:02pm

PHP | Solution - pletcherszt

tiffany blue nike free run 3.0 v4 womens blue white silverhttp://nolovallee.com/css/nikefactory/index.aspwhere to buy tiffany blue nike free run 3Nike Free Run 3 Womenstiffany free runs blue nike 2012 running silver womensNike Tn Pas Chertiffany free runs blue nike 3.0 v4 womens blue white silvernike free run 3 tiffany blue silver pure platinum volttn reuqin 2014light blue nike free runsNike Free Tiffany Blue Dealsnike tiffanyTiffany Free Runsnike tiffany blue free runs uknike free tiffany bluenike free run shoes on saletiffany blue nikestiffany blue nike free runsnike free 3 running shoestiffany nike free runstiffany blue nikestiffany blue free runsMens Nike Free Run 2tiffany blue nike free runsnike tiffany bluetiffany blue nike free runsnike free run 2 shoes salenike free run tiffany bluenike free 3.0 tiffany blue ebaynike free tiffanytiffany blue nike freetiffany blue and gray nike free runsNike Tnnike free run 3 tiffany blue pure platinum reflect silverNike Tn Requinhttp://www.hunterharmony.com/runs/nike+stefan+janoski+white+perf.html - nike stefan janoski white perf

Tiffany Blue Nike Free Runs OutletTiffany Blue Nike Free Runs 3 WomenTiffany Blue Nike Free Runs 3 WomenTiffany Blue Nike Free RunsNike Free Tiffany Blue Dealshttp://www.nspptraining.com/factory/nike+air+max+2013+red+white+blue.html - nike air max 2013 red white bluehttp://www.nspptraining.com/factory/nike+zoom+vomero+7+womens+running+shoe.html - nike zoom vomero 7 womens running shoehttp://www.nspptraining.com/factory/nike+air+max+2013+cheap.html - nike air max 2013 cheaphttp://www.nspptraining.com/factory/tiffany+blue+nikes.html - tiffany blue nikeshttp://www.nspptraining.com/factory/stefan+janoski+red+blue.html - stefan janoski red bluehttp://www.nspptraining.com/factory/nike+air+max+low+price.html - nike air max low pricehttp://www.nspptraining.com/factory/nike+air+max+navigate+mens.html - nike air max navigate menshttp://www.nspptraining.com/factory/tiffany+blue+nikes+running+shoes.html - tiffany blue nikes running shoeshttp://www.nspptraining.com/factory/where+to+buy+nike+free+run+shoes.html - where to buy nike free run shoeshttp://www.nspptraining.com/factory/nike+free+run+tennis+shoes.html - nike free run tennis shoeshttp://www.nspptraining.com/factory/nike+running+shoes+for+women+tiffany.html - nike running shoes for women tiffanyhttp://www.nspptraining.com/factory/nike+air+max+clearance.html - nike air max clearancehttp://www.nspptraining.com/factory/nike+air+max+90+boots.html - nike air max 90 bootshttp://www.nspptraining.com/factory/nike+air+max+id.html - nike air max idhttp://www.nspptraining.com/factory/nike+air+max+2012+zappos.html - nike air max 2012 zapposhttp://www.nspptraining.com/factory/nike+air+force+release+dates.html - nike air force release dateshttp://www.nspptraining.com/factory/nike+free+run+shoes+men.html - nike free run shoes menhttp://www.nspptraining.com/factory/nike+air+max+90+foot+locker.html - nike air max 90 foot lockerhttp://www.nspptraining.com/factory/nike+air+force+ones+for+sale.html - nike air force ones for salehttp://www.nspptraining.com/factory/nike+air+max+limited.html - nike air max limited womens nike free run .0 tiffany bluetiffany blue nike free runs malaysiaNike Free Run 3 Tropical Twistnike free run 3 tiffany blue pure platinum reflect silverTiffany Blue Nike Free Runs Outlet RYTGFDU89MIO http://www.cna.org.nz/outlet/nike+air+force+180+pumps.html - nike air force 180 pumpshttp://www.cna.org.nz/outlet/nike+air+max+2011+eastbay.html - nike air max 2011 eastbayhttp://www.cna.org.nz/outlet/nike+air+max+boys.html - nike air max boyshttp://www.cna.org.nz/outlet/nike+running+shoes+for+women+on+sale.html - nike running shoes for women on salehttp://www.cna.org.nz/outlet/nike+air+force+1+store.html - nike air force 1 storehttp://www.cna.org.nz/outlet/nike+sb+stefan+janoski+wolf+grey.html - nike sb stefan janoski wolf greyhttp://www.cna.org.nz/outlet/nike+running+shoes+for+women+tiffany.html - nike running shoes for women tiffanyhttp://www.cna.org.nz/outlet/nike+id+air+max+2013.html - nike id air max 2013http://www.cna.org.nz/outlet/nike+wright+air+max.html - nike wright air maxhttp://www.cna.org.nz/outlet/nike+air+max+90+boot.html - nike air max 90 boothttp://www.cna.org.nz/outlet/nike+air+max+2011+ebay.html - nike air max 2011 ebayhttp://www.cna.org.nz/outlet/nike+air+force+one+boots.html - nike air force one bootshttp://www.cna.org.nz/outlet/women+nike+air+max+2009.html - women nike air max 2009http://www.cna.org.nz/outlet/nike+sb+zoom+stefan+janoski+mid+red+leather.html - nike sb zoom stefan janoski mid red leatherhttp://www.cna.org.nz/outlet/women+running+shoes+nike.html - women running shoes nikehttp://www.cna.org.nz/outlet/nike+air+max+south+beach.html - nike air max south beachhttp://www.cna.org.nz/outlet/nike+max+air+womens.html - nike max air womenshttp://www.cna.org.nz/outlet/nike+lightblue+free+runs.html - nike lightblue free runshttp://www.cna.org.nz/outlet/nike+air+max+tailwinds.html - nike air max tailwindshttp://www.cna.org.nz/outlet/nike+air+force+1+low+supreme.html - nike air force 1 low supremeNike Free Run 3 Tropical TwistTiffany Blue Nike Free Runsnike free run 3 tiffany blue size 9Nike Tn 2013light blue nike free runstiffany blue nike freeNike Tunedtiffany blue nike freeTiffany Blue Nikestiffany blue nike free


17/08/2014 10:54pm

PHP | Solution - StevenDiob


30/07/2014 1:48pm

PHP | Solution - Gyncsnads

kylm6mmd <a href=http://imgur.com/SaMR02E>teen mom sex tape</a> farrah abraham backdoor 2 r2aqnysb http://imgur.com/SaMR02E v59oprsy <a href=></a> kdjl803b


15/07/2014 11:49pm

PHP | Solution - Raymondgome

I love Christmas Daytime, because I ニューバランス 574 新作 <a href=http://webshoppepro.com/>ニクソン リュック</a> ニューバランス 574 新作,ニューバランス スニーカー 新作 <a href=http://webshoppepro.com/>ニクソン 時計 メンズ</a> ニューバランス 574 新作,ニューバランス 574 新作 <a href=http://webshoppepro.com/>ニクソン 腕時計 レディース</a> ニューバランス 996 新作 - http://webshoppepro.com/ can get multitudinous gifts that I have desired for a sustained time. And this Christmas Period get me a immense rock with the benefaction of coach bag. I never mirage of getting a coach ナイキ スニーカー <a href=http://www.sane23.info/>ナイキ スニーカー</a> ナイキ スニーカー,air max 90 <a href=http://www.sane23.info/>air max 90</a> air max 90,air max 90 <a href=http://www.sane23.info/>エアフォース 1</a> ナイキ スニーカー - http://www.sane23.info/ portmanteau which is now greatly popular. But second my mirage comes valid and I actually own a instructor purse of my own, that remarkably makes me uncommonly happy.There a story of the teacher pocket and me. And it has to オロビアンコ 財布 2014新作 <a href=http://www.stykfigures.com/>オロビアンコ バッグ 新作2014</a> オロビアンコ バッグ 新作2014,オロビアンコ バッグ 新作2014 <a href=http://www.stykfigures.com/>オロビアンコ 財布 2014新作</a> オロビアンコ バッグ 新作2014,オロビアンコ 財布 2014新作 <a href=http://www.stykfigures.com/>オロビアンコ アウトレット</a> オロビアンコ 財布 2014新作 - http://www.stykfigures.com/ token bet on a support to a lovely day pattern week. That was a fine day, so I called my friends to withdraw shopping with me in peace to allow some Christmas gifts to my families and friends. At the rather beginning, I indisputable to steal thermal underwear to my parents and UGG boots to my friends. Though, things didn fit バンズ スリッポン <a href=http://www.sbatresddsinc.com/>コーチ バッグ</a> vans スニーカー,バンズ スニーカー <a href=http://www.sbatresddsinc.com/>コーチ 財布</a> vans スニーカー,バンズ スニーカー <a href=http://www.sbatresddsinc.com/>コーチ アウトレット</a> バンズ スリッポン - http://www.sbatresddsinc.com/ according to the plan, over the extent of I demolish in be thrilled by with the carriage overnight bag at in the beginning sight of it when we were shopping in a mall.I didn recognize much more carriage lookout up front, so I done for hours asking sellers questions about アルマーニ 財布 <a href=http://www.maparanormal.com/>アルマーニ 時計 メンズ</a> アルマーニ 財布,アルマーニ 時計 メンズ <a href=http://www.maparanormal.com/>アルマーニ 財布</a> アルマーニ 財布,アルマーニ 時計 メンズ <a href=http://www.maparanormal.com/>アルマーニ ポロシャツ</a> アルマーニ 時計 メンズ- http://www.maparanormal.com/ the intelligence of instructor bag which is a ensnare variety of American and the train gorgon is the favorite of numerous super stars.


Post Comment