AbstractTool.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace Dcat\Admin\Grid\Tools;
  3. use Dcat\Admin\Grid;
  4. use Illuminate\Contracts\Support\Renderable;
  5. abstract class AbstractTool implements Renderable
  6. {
  7. /**
  8. * @var Grid
  9. */
  10. protected $grid;
  11. /**
  12. * @var bool
  13. */
  14. protected $disabled = false;
  15. /**
  16. * Toggle this button.
  17. *
  18. * @param bool $disable
  19. *
  20. * @return $this
  21. */
  22. public function disable(bool $disable = true)
  23. {
  24. $this->disabled = $disable;
  25. return $this;
  26. }
  27. /**
  28. * If the tool is allowed.
  29. */
  30. public function allowed()
  31. {
  32. return !$this->disabled;
  33. }
  34. /**
  35. * Set parent grid.
  36. *
  37. * @param Grid $grid
  38. *
  39. * @return $this
  40. */
  41. public function setGrid(Grid $grid)
  42. {
  43. $this->grid = $grid;
  44. return $this;
  45. }
  46. /**
  47. * {@inheritdoc}
  48. */
  49. abstract public function render();
  50. /**
  51. * @return string
  52. */
  53. public function __toString()
  54. {
  55. return $this->render();
  56. }
  57. }