← All changes
|
backend/src/ValueObjects/Field/FieldAdvancedSettings.php
+154
-17
0.4
→
1.5
View file →
| @@ -1,20 +1,13 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | /** |
| 4 | - * @copyright © TMS-Plugins. All rights reserved. | |
| 4 | + * @copyright © Melograno Venture Studio. All rights reserved. | |
| 5 | 5 | * @licence See LICENCE.md for license details. |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | namespace IvyForms\ValueObjects\Field; |
| 9 | 9 | |
| 10 | -// phpcs:disable PSR1.Files.SideEffects | |
| 11 | -if (!defined('ABSPATH')) { | |
| 12 | - exit; // Exit if accessed directly | |
| 13 | -} | |
| 14 | - | |
| 15 | -use IvyForms\Common\Exceptions\ValidationException; | |
| 16 | - | |
| 17 | 10 | /** |
| 18 | 11 | * Class FieldAdvancedSettings |
| 19 | 12 | * |
| 20 | 13 | * @package IvyForms\ValueObjects\Field |
| @@ -46,8 +39,28 @@ | ||
| 46 | 39 | */ |
| 47 | 40 | public bool $noDuplicates; |
| 48 | 41 | |
| 49 | 42 | /** |
| 43 | + * @var string field prefix (e.g., https://) | |
| 44 | + */ | |
| 45 | + private string $inputPrefix; | |
| 46 | + | |
| 47 | + /** | |
| 48 | + * @var string field suffix (e.g., .com) | |
| 49 | + */ | |
| 50 | + private string $inputSuffix; | |
| 51 | + | |
| 52 | + /** | |
| 53 | + * @var string Type of rating icon (star, heart, etc.) | |
| 54 | + */ | |
| 55 | + private string $ratingIcon; | |
| 56 | + | |
| 57 | + /** | |
| 58 | + * @var FileUploadFieldAdvancedSettings | |
| 59 | + */ | |
| 60 | + private FileUploadFieldAdvancedSettings $fileUploadSettings; | |
| 61 | + | |
| 62 | + /** | |
| 50 | 63 | * FieldAdvancedSettings constructor. |
| 51 | 64 | * |
| 52 | 65 | * @param string $defaultValue |
| 53 | 66 | * @param bool $limitMaxLength |
| @@ -53,9 +66,12 @@ | ||
| 53 | 66 | * @param bool $limitMaxLength |
| 54 | 67 | * @param int $maxLength |
| 55 | 68 | * @param string $labelPosition |
| 56 | 69 | * @param bool $noDuplicates |
| 57 | - * | |
| 70 | + * @param string $inputPrefix | |
| 71 | + * @param string $inputSuffix | |
| 72 | + * @param string $ratingIcon | |
| 73 | + * @param FileUploadFieldAdvancedSettings $fileUploadSettings | |
| 58 | 74 | */ |
| 59 | 75 | public function __construct( |
| 60 | 76 | string $defaultValue, |
| 61 | 77 | bool $limitMaxLength, |
| @@ -60,9 +76,13 @@ | ||
| 60 | 76 | string $defaultValue, |
| 61 | 77 | bool $limitMaxLength, |
| 62 | 78 | int $maxLength, |
| 63 | 79 | string $labelPosition, |
| 64 | - bool $noDuplicates | |
| 80 | + bool $noDuplicates, | |
| 81 | + string $inputPrefix, | |
| 82 | + string $inputSuffix, | |
| 83 | + string $ratingIcon, | |
| 84 | + FileUploadFieldAdvancedSettings $fileUploadSettings | |
| 65 | 85 | ) { |
| 66 | 86 | $this->defaultValue = $defaultValue; |
| 67 | 87 | $this->limitMaxLength = $limitMaxLength; |
| 68 | 88 | $this->maxLength = $maxLength; |
| @@ -67,8 +87,12 @@ | ||
| 67 | 87 | $this->limitMaxLength = $limitMaxLength; |
| 68 | 88 | $this->maxLength = $maxLength; |
| 69 | 89 | $this->labelPosition = $labelPosition; |
| 70 | 90 | $this->noDuplicates = $noDuplicates; |
| 91 | + $this->inputPrefix = $inputPrefix; | |
| 92 | + $this->inputSuffix = $inputSuffix; | |
| 93 | + $this->ratingIcon = $ratingIcon; | |
| 94 | + $this->fileUploadSettings = $fileUploadSettings; | |
| 71 | 95 | } |
| 72 | 96 | |
| 73 | 97 | /** |
| 74 | 98 | * Get the default value. |
| @@ -170,8 +194,115 @@ | ||
| 170 | 194 | $this->noDuplicates = $noDuplicates; |
| 171 | 195 | } |
| 172 | 196 | |
| 173 | 197 | /** |
| 198 | + * Get the field prefix. | |
| 199 | + * | |
| 200 | + * @return string | |
| 201 | + */ | |
| 202 | + public function getInputPrefix(): string | |
| 203 | + { | |
| 204 | + return $this->inputPrefix; | |
| 205 | + } | |
| 206 | + | |
| 207 | + /** | |
| 208 | + * Set the field prefix. | |
| 209 | + * | |
| 210 | + * @param string $prefix | |
| 211 | + */ | |
| 212 | + public function setInputPrefix(string $prefix): void | |
| 213 | + { | |
| 214 | + $this->inputPrefix = $prefix; | |
| 215 | + } | |
| 216 | + | |
| 217 | + /** | |
| 218 | + * Get the field suffix. | |
| 219 | + * | |
| 220 | + * @return string | |
| 221 | + */ | |
| 222 | + public function getInputSuffix(): string | |
| 223 | + { | |
| 224 | + return $this->inputSuffix; | |
| 225 | + } | |
| 226 | + | |
| 227 | + /** | |
| 228 | + * Set the field suffix. | |
| 229 | + * | |
| 230 | + * @param string $suffix | |
| 231 | + */ | |
| 232 | + public function setInputSuffix(string $suffix): void | |
| 233 | + { | |
| 234 | + $this->inputSuffix = $suffix; | |
| 235 | + } | |
| 236 | + | |
| 237 | + /** | |
| 238 | + * Get the rating icon type. | |
| 239 | + * | |
| 240 | + * @return string | |
| 241 | + */ | |
| 242 | + public function getRatingIcon(): string | |
| 243 | + { | |
| 244 | + return $this->ratingIcon; | |
| 245 | + } | |
| 246 | + | |
| 247 | + /** | |
| 248 | + * Set the rating icon type. | |
| 249 | + * | |
| 250 | + * @param string $ratingIcon | |
| 251 | + */ | |
| 252 | + public function setRatingIcon(string $ratingIcon): void | |
| 253 | + { | |
| 254 | + $this->ratingIcon = $ratingIcon; | |
| 255 | + } | |
| 256 | + | |
| 257 | + public function getFileUploadSettings(): FileUploadFieldAdvancedSettings | |
| 258 | + { | |
| 259 | + return $this->fileUploadSettings; | |
| 260 | + } | |
| 261 | + | |
| 262 | + /** | |
| 263 | + * Maximum file size in MB for file-upload fields (0 = server default). | |
| 264 | + */ | |
| 265 | + public function getMaxFileSizeMb(): int | |
| 266 | + { | |
| 267 | + return $this->fileUploadSettings->getMaxFileSizeMb(); | |
| 268 | + } | |
| 269 | + | |
| 270 | + public function setMaxFileSizeMb(int $maxFileSizeMb): void | |
| 271 | + { | |
| 272 | + $this->fileUploadSettings->setMaxFileSizeMb($maxFileSizeMb); | |
| 273 | + } | |
| 274 | + | |
| 275 | + /** | |
| 276 | + * Target storage for uploads: ivyforms or media_library. | |
| 277 | + */ | |
| 278 | + public function getSaveUploadsTo(): string | |
| 279 | + { | |
| 280 | + return $this->fileUploadSettings->getSaveUploadsTo(); | |
| 281 | + } | |
| 282 | + | |
| 283 | + public function setSaveUploadsTo(string $saveUploadsTo): void | |
| 284 | + { | |
| 285 | + $this->fileUploadSettings->setSaveUploadsTo($saveUploadsTo); | |
| 286 | + } | |
| 287 | + | |
| 288 | + /** | |
| 289 | + * @return array<int, string> | |
| 290 | + */ | |
| 291 | + public function getAllowedFileExtensions(): array | |
| 292 | + { | |
| 293 | + return $this->fileUploadSettings->getAllowedFileExtensions(); | |
| 294 | + } | |
| 295 | + | |
| 296 | + /** | |
| 297 | + * @param array<int, string> $allowedFileExtensions | |
| 298 | + */ | |
| 299 | + public function setAllowedFileExtensions(array $allowedFileExtensions): void | |
| 300 | + { | |
| 301 | + $this->fileUploadSettings->setAllowedFileExtensions($allowedFileExtensions); | |
| 302 | + } | |
| 303 | + | |
| 304 | + /** | |
| 174 | 305 | * Convert the advanced settings to an array. |
| 175 | 306 | * |
| 176 | 307 | * @return array<string, mixed> |
| 177 | 308 | */ |
| @@ -176,13 +307,19 @@ | ||
| 176 | 307 | * @return array<string, mixed> |
| 177 | 308 | */ |
| 178 | 309 | public function toArray(): array |
| 179 | 310 | { |
| 180 | - return [ | |
| 181 | - 'defaultValue' => $this->getDefaultValue(), | |
| 182 | - 'limitMaxLength' => $this->isLimitMaxLength(), | |
| 183 | - 'maxLength' => $this->getMaxLength(), | |
| 184 | - 'labelPosition' => $this->getLabelPosition(), | |
| 185 | - 'noDuplicates' => $this->isNoDuplicates(), | |
| 186 | - ]; | |
| 311 | + return array_merge( | |
| 312 | + [ | |
| 313 | + 'defaultValue' => $this->getDefaultValue(), | |
| 314 | + 'limitMaxLength' => $this->isLimitMaxLength(), | |
| 315 | + 'maxLength' => $this->getMaxLength(), | |
| 316 | + 'labelPosition' => $this->getLabelPosition(), | |
| 317 | + 'noDuplicates' => $this->isNoDuplicates(), | |
| 318 | + 'inputPrefix' => $this->getInputPrefix(), | |
| 319 | + 'inputSuffix' => $this->getInputSuffix(), | |
| 320 | + 'ratingIcon' => $this->getRatingIcon(), | |
| 321 | + ], | |
| 322 | + $this->fileUploadSettings->toArray() | |
| 323 | + ); | |
| 187 | 324 | } |
| 188 | 325 | } |