Source of file GridFieldRowLink.php
Size: 5,080 Bytes - Last Modified: 2021-12-23T10:00:19+00:00
/var/www/docs.ssmods.com/process/src/src/GridFieldRowLink.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 | <?php namespace LeKoala\CmsActions; use SilverStripe\View\SSViewer; use SilverStripe\ORM\DataObject; use SilverStripe\View\ArrayData; use SilverStripe\Control\Controller; use SilverStripe\Forms\GridField\GridField_ColumnProvider; /** * Provides a custom link for a single record * * Links do not trigger actions, use GridFieldRowButton instead */ class GridFieldRowLink implements GridField_ColumnProvider { /** * HTML classes to be added to GridField buttons * * @var string[] */ protected $extraClass = [ 'grid-field__icon-action--hidden-on-hover' => true, 'btn--icon-large' => true ]; /** * @var string */ protected $name; /** * @var string */ protected $title; /** * @var boolean */ protected $newWindow = true; /** * @param string $name * @param string $title * @param string $icon */ public function __construct($name, $title, $icon = 'white-question') { $this->name = $name; $this->title = $title; $this->addExtraClass('font-icon-' . $icon); } /** * Add a column 'Actions' * * @param GridField $gridField * @param array $columns */ public function augmentColumns($gridField, &$columns) { if (!in_array('Actions', $columns)) { $columns[] = 'Actions'; } } /** * Return any special attributes that will be used for FormField::create_tag() * * @param GridField $gridField * @param DataObject $record * @param string $columnName * @return array */ public function getColumnAttributes($gridField, $record, $columnName) { return array('class' => 'grid-field__col-compact'); } /** * Add the title * * @param GridField $gridField * @param string $columnName * @return array */ public function getColumnMetadata($gridField, $columnName) { if ($columnName == 'Actions') { return array('title' => ''); } return []; } /** * Which columns are handled by this component * * @param GridField $gridField * @return array */ public function getColumnsHandled($gridField) { return array('Actions'); } /** * @param GridField $gridField * @param DataObject $record * @param string $columnName * @return string The link to the action */ public function getLink($gridField, $record, $columnName) { return Controller::join_links($gridField->Link('item'), $record->ID, $this->name); } /** * @param GridField $gridField * @param DataObject $record * @param string $columnName * @return string The HTML for the column */ public function getColumnContent($gridField, $record, $columnName) { if ($this->newWindow) { $this->addExtraClass('no-ajax'); } $data = new ArrayData(array( 'Link' => $this->getLink($gridField, $record, $columnName), 'ExtraClass' => $this->getExtraClass(), 'Title' => $this->title, 'NewWindow' => $this->newWindow, )); $template = SSViewer::get_templates_by_class($this, '', __CLASS__); return $data->renderWith($template); } /** * Get the extra HTML classes to add for edit buttons * * @return string */ public function getExtraClass() { return implode(' ', array_keys($this->extraClass)); } /** * Add an extra HTML class * * @param string $class * @return $this */ public function addExtraClass($class) { $this->extraClass[$class] = true; return $this; } /** * Remove an HTML class * * @param string $class * @return $this */ public function removeExtraClass($class) { unset($this->extraClass[$class]); return $this; } /** * Get the value of name * * @return string */ public function getName() { return $this->name; } /** * Set the value of name * * @param string $name * * @return $this */ public function setName(string $name) { $this->name = $name; return $this; } /** * Get the value of title * * @return string */ public function getTitle() { return $this->title; } /** * Set the value of title * * @param string $title * * @return $this */ public function setTitle(string $title) { $this->title = $title; return $this; } /** * Get the value of newWindow */ public function getNewWindow() { return $this->newWindow; } /** * Set the value of newWindow * * @return $this */ public function setNewWindow($newWindow) { $this->newWindow = $newWindow; return $this; } } |