PageDataRequest.php
3 weeks ago
PageRequest.php
3 weeks ago
PageSettingsRequest.php
3 weeks ago
PageUpdateRequest.php
3 weeks ago
PopupRequest.php
3 weeks ago
TogglePageSymbolRequest.php
3 weeks ago
PageRequest.php
62 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Kirki\App\Http\Requests\Page; |
| 4 | |
| 5 | defined('ABSPATH') || exit; |
| 6 | |
| 7 | use Kirki\App\Constants\PostTypes; |
| 8 | use Kirki\App\Constants\UtilityPageType; |
| 9 | use Kirki\App\Services\UtilityPageService; |
| 10 | use Kirki\Framework\Http\Request; |
| 11 | use Kirki\Framework\Sanitizer; |
| 12 | |
| 13 | class PageRequest extends Request |
| 14 | { |
| 15 | public function rules() |
| 16 | { |
| 17 | return [ |
| 18 | 'post_title' => 'required|string', |
| 19 | 'post_type' => 'required|string', |
| 20 | 'blocks' => 'nullable|array', |
| 21 | 'conditions' => 'nullable|array', |
| 22 | 'collection_type' => 'nullable|string', |
| 23 | 'utility_page_type' => [ |
| 24 | 'nullable', |
| 25 | 'string', |
| 26 | 'in:' . UtilityPageType::join(), |
| 27 | function ($value) { |
| 28 | if ($this->post_type === PostTypes::UTILITY) { |
| 29 | if (empty($value)) { |
| 30 | return __("Utility page type is required.", 'kirki'); |
| 31 | } |
| 32 | |
| 33 | $exists = UtilityPageService::create()->exists($value); |
| 34 | |
| 35 | if ($exists) { |
| 36 | /** translators: %s: Utility page type */ |
| 37 | return sprintf(__("Utility page of type %s already exists."), $value); |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | return true; |
| 42 | } |
| 43 | ], |
| 44 | 'custom_template' => 'nullable|array', |
| 45 | 'custom_template.url' => 'nullable|url', |
| 46 | ]; |
| 47 | } |
| 48 | |
| 49 | public function filters() |
| 50 | { |
| 51 | return [ |
| 52 | 'post_title' => Sanitizer::TEXT, |
| 53 | 'post_type' => Sanitizer::TEXT, |
| 54 | 'blocks' => Sanitizer::ARRAY, |
| 55 | 'conditions' => Sanitizer::ARRAY, |
| 56 | 'collection_type' => Sanitizer::TEXT, |
| 57 | 'utility_page_type' => Sanitizer::TEXT, |
| 58 | 'custom_template' => Sanitizer::ARRAY, |
| 59 | 'custom_template.url' => Sanitizer::URL, |
| 60 | ]; |
| 61 | } |
| 62 | } |