Actions
2 years ago
BlockModels
2 years ago
BlockTypes
2 years ago
Controllers
1 year ago
DataTransferObjects
2 years ago
EmailPreview
2 years ago
Routes
1 year ago
ValueObjects
2 years ago
ViewModels
2 years ago
resources
1 year ago
FormBuilderRouteBuilder.php
2 years ago
ServiceProvider.php
1 year ago
FormBuilderRouteBuilder.php
72 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\FormBuilder; |
| 4 | |
| 5 | class FormBuilderRouteBuilder |
| 6 | { |
| 7 | const SLUG = 'givewp-form-builder'; |
| 8 | |
| 9 | /** |
| 10 | * @var int|string |
| 11 | */ |
| 12 | protected $donationFormID; |
| 13 | |
| 14 | /** |
| 15 | * @since 3.0.0 |
| 16 | * |
| 17 | * @param int|string $donationFormID |
| 18 | */ |
| 19 | protected function __construct($donationFormID) |
| 20 | { |
| 21 | $this->donationFormID = $donationFormID; |
| 22 | } |
| 23 | |
| 24 | /** |
| 25 | * @since 3.0.0 |
| 26 | */ |
| 27 | public static function makeCreateFormRoute(): self |
| 28 | { |
| 29 | // @todo Refactor create route so as not to mix types for $donationFormID. |
| 30 | return new self('new'); |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * @since 3.0.0 |
| 35 | */ |
| 36 | public static function makeEditFormRoute(int $donationFormID): self |
| 37 | { |
| 38 | return new self($donationFormID); |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * @since 3.0.0 |
| 43 | */ |
| 44 | public function __toString() |
| 45 | { |
| 46 | return $this->getUrl(); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * @since 3.0.0 |
| 51 | */ |
| 52 | public function getUrl(): string |
| 53 | { |
| 54 | return add_query_arg( |
| 55 | [ |
| 56 | 'post_type' => 'give_forms', |
| 57 | 'page' => self::SLUG, |
| 58 | 'donationFormID' => $this->donationFormID, |
| 59 | ], |
| 60 | admin_url('edit.php') |
| 61 | ); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * @since 3.0.0 |
| 66 | */ |
| 67 | public static function isRoute(): bool |
| 68 | { |
| 69 | return isset($_GET['post_type'], $_GET['page']) && $_GET['post_type'] === 'give_forms' && $_GET['page'] === self::SLUG; |
| 70 | } |
| 71 | } |
| 72 |