ResetCommentsTable.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace App\Model\Table;
  3. use Cake\ORM\Entity;
  4. use Tools\Model\Table\Table;
  5. class ResetCommentsTable extends Table {
  6. /**
  7. * @param array $config
  8. * @return void
  9. */
  10. public function initialize(array $config) {
  11. $this->displayField('comment');
  12. parent::initialize($config);
  13. }
  14. /**
  15. * @param \Cake\ORM\Entity $record
  16. * @param array $updateFields
  17. * @return \Cake\ORM\Entity
  18. */
  19. public function customCallback(Entity $record, &$updateFields) {
  20. $record->comment .= ' xyz';
  21. $fields[] = 'some_other_field';
  22. return $record;
  23. }
  24. /**
  25. * @param \Cake\ORM\Entity $record
  26. * @param array $updateFields
  27. * @return \Cake\ORM\Entity
  28. */
  29. public function customObjectCallback(Entity $record, &$updateFields) {
  30. $record['comment'] .= ' xxx';
  31. $updateFields[] = 'some_other_field';
  32. return $record;
  33. }
  34. /**
  35. * @param \Cake\ORM\Entity $record
  36. * @param array $updateFields
  37. * @return \Cake\ORM\Entity
  38. */
  39. public static function customStaticCallback(Entity $record, &$updateFields) {
  40. $record['comment'] .= ' yyy';
  41. $updateFields[] = 'some_other_field';
  42. return $record;
  43. }
  44. /**
  45. * @param \Cake\ORM\Entity $record
  46. * @param array $updateFields
  47. * @return \Cake\ORM\Entity
  48. */
  49. public static function fieldsCallback(Entity $record, &$updateFields) {
  50. $record['comment'] = 'foo';
  51. return $record;
  52. }
  53. /**
  54. * @param \Cake\ORM\Entity $record
  55. * @param array $updateFields
  56. * @return \Cake\ORM\Entity
  57. */
  58. public static function fieldsCallbackAuto(Entity $record, &$updateFields) {
  59. $record['comment'] = 'bar';
  60. $updateFields[] = 'comment';
  61. return $record;
  62. }
  63. }