TestUsingViewWidget.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  5. * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  6. *
  7. * Licensed under The MIT License
  8. * Redistributions of files must retain the above copyright notice.
  9. *
  10. * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  11. * @link https://cakephp.org CakePHP(tm) Project
  12. * @since 4.0.0
  13. * @license https://opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace TestApp\View\Widget;
  16. use Cake\View\Form\ContextInterface;
  17. use Cake\View\StringTemplate;
  18. use Cake\View\View;
  19. use Cake\View\Widget\WidgetInterface;
  20. class TestUsingViewWidget implements WidgetInterface
  21. {
  22. protected $_templates;
  23. protected $_view;
  24. public function __construct(StringTemplate $templates, View $view)
  25. {
  26. $this->_templates = $templates;
  27. $this->_view = $view;
  28. }
  29. public function getView(): View
  30. {
  31. return $this->_view;
  32. }
  33. /**
  34. * @inheritDoc
  35. */
  36. public function render(array $data, ContextInterface $context): string
  37. {
  38. return '<success></success>';
  39. }
  40. /**
  41. * @inheritDoc
  42. */
  43. public function secureFields(array $data): array
  44. {
  45. if (!isset($data['name']) || $data['name'] === '') {
  46. return [];
  47. }
  48. return [$data['name']];
  49. }
  50. }