DropdownActions.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. namespace Dcat\Admin\Grid\Displayers;
  3. use Dcat\Admin\Support\Helper;
  4. class DropdownActions extends Actions
  5. {
  6. protected $view = 'admin::grid.dropdown-actions';
  7. /**
  8. * @var array
  9. */
  10. protected $default = [];
  11. public function prepend($action)
  12. {
  13. return $this->append($action);
  14. }
  15. /**
  16. * @param mixed $action
  17. *
  18. * @return mixed
  19. */
  20. protected function prepareAction(&$action)
  21. {
  22. parent::prepareAction($action);
  23. return $action = $this->wrapCustomAction($action);
  24. }
  25. /**
  26. * @param mixed $action
  27. *
  28. * @return string
  29. */
  30. protected function wrapCustomAction($action)
  31. {
  32. $action = Helper::render($action);
  33. if (mb_strpos($action, '</a>') === false) {
  34. return "<a>$action</a>";
  35. }
  36. return $action;
  37. }
  38. /**
  39. * Prepend default `edit` `view` `delete` actions.
  40. */
  41. protected function prependDefaultActions()
  42. {
  43. foreach ($this->actions as $action => $enable) {
  44. if (! $enable) {
  45. continue;
  46. }
  47. array_push($this->default, $this->{'render'.ucfirst($action)}());
  48. }
  49. }
  50. /**
  51. * @param \Closure[] $callback
  52. *
  53. * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
  54. */
  55. public function display(array $callbacks = [])
  56. {
  57. $this->resetDefaultActions();
  58. $this->call($callbacks);
  59. $this->prependDefaultActions();
  60. $actions = [
  61. 'default' => $this->default,
  62. 'custom' => $this->appends,
  63. 'selector' => ".{$this->grid->getRowName()}-checkbox",
  64. ];
  65. return view($this->view, $actions);
  66. }
  67. protected function getViewLabel()
  68. {
  69. }
  70. protected function getEditLabel()
  71. {
  72. }
  73. protected function getQuickEditLabel()
  74. {
  75. }
  76. protected function getDeleteLabel()
  77. {
  78. }
  79. }