silverleague /
silverstripe-logviewer
| 1 | <?php |
||
| 2 | |||
| 3 | namespace SilverLeague\LogViewer\Admin; |
||
| 4 | |||
| 5 | use SilverLeague\LogViewer\Model\LogEntry; |
||
| 6 | use SilverLeague\LogViewer\Forms\GridField\GridFieldClearAllButton; |
||
| 7 | use SilverStripe\Admin\ModelAdmin; |
||
| 8 | use SilverStripe\Forms\GridField\GridFieldAddNewButton; |
||
| 9 | use SilverStripe\View\Requirements; |
||
| 10 | |||
| 11 | /** |
||
| 12 | * Creates a CMS interface for viewing log entries |
||
| 13 | * |
||
| 14 | * @package silverstripe-logviewer |
||
| 15 | * @author Robbie Averill <[email protected]> |
||
| 16 | */ |
||
| 17 | class LogViewerAdmin extends ModelAdmin |
||
| 18 | { |
||
| 19 | private static $url_segment = 'logs'; |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 20 | |||
| 21 | private static $menu_title = 'Logs'; |
||
|
0 ignored issues
–
show
|
|||
| 22 | |||
| 23 | private static $menu_icon_class = 'font-icon-list'; |
||
|
0 ignored issues
–
show
|
|||
| 24 | |||
| 25 | private static $managed_models = [ |
||
|
0 ignored issues
–
show
|
|||
| 26 | LogEntry::class |
||
| 27 | ]; |
||
| 28 | |||
| 29 | public $showImportForm = false; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * Add log viewer custom CSS styles |
||
| 33 | * |
||
| 34 | * {@inheritDoc} |
||
| 35 | */ |
||
| 36 | protected function init() |
||
| 37 | { |
||
| 38 | parent::init(); |
||
| 39 | Requirements::css('silverleague/logviewer:client/dist/styles/logviewer.css'); |
||
| 40 | } |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Remove the "add new" button |
||
| 44 | * |
||
| 45 | * {@inheritDoc} |
||
| 46 | */ |
||
| 47 | public function getEditForm($id = null, $fields = null) |
||
| 48 | { |
||
| 49 | $form = parent::getEditForm($id, $fields); |
||
| 50 | |||
| 51 | $gridField = $form->Fields()->fieldByName($this->getGridFieldName()); |
||
| 52 | |||
| 53 | /** @var \SilverStripe\Forms\GridField\GridFieldConfig $gridFieldConfig */ |
||
| 54 | $config = $gridField->getConfig(); |
||
| 55 | $config->removeComponentsByType($config->getComponentByType(GridFieldAddNewButton::class)); |
||
| 56 | $config->addComponent(new GridFieldClearAllButton('buttons-before-left')); |
||
| 57 | |||
| 58 | return $form; |
||
| 59 | } |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Get the FieldList name for the GridField |
||
| 63 | * |
||
| 64 | * @return string |
||
| 65 | */ |
||
| 66 | public function getGridFieldName() |
||
| 67 | { |
||
| 68 | return $this->sanitiseClassName($this->modelClass); |
||
| 69 | } |
||
| 70 | |||
| 71 | /** |
||
| 72 | * Display newest log entries first |
||
| 73 | * |
||
| 74 | * {@inheritDoc} |
||
| 75 | */ |
||
| 76 | public function getList() |
||
| 77 | { |
||
| 78 | $list = parent::getList(); |
||
| 79 | return $list->sort(['Created' => 'DESC']); |
||
| 80 | } |
||
| 81 | } |
||
| 82 |