diff --git a/.gitignore b/.gitignore index 6c8a8d35b..cb2411ab7 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,10 @@ node_modules /saturn /dist/hot /resources/assets/dist +.mcp.json +.claude +.gemini +AGENTS.md +GEMINI.md +opencode.jsonc +.codegraph diff --git a/docs/.vitepress/sidebar.ts b/docs/.vitepress/sidebar.ts index dc5b7bf90..701ff9e67 100644 --- a/docs/.vitepress/sidebar.ts +++ b/docs/.vitepress/sidebar.ts @@ -44,7 +44,6 @@ export function sidebar(): DefaultTheme.SidebarItem[] { { text: 'List', link: '/guide/form-fields/list.md' }, { text: 'AutocompleteList', link: '/guide/form-fields/autocomplete-list.md' }, { text: 'Geolocation', link: '/guide/form-fields/geolocation.md' }, - { text: 'Multi-Forms (deprecated)', link: '/guide/multiforms.md' }, // { text: 'Custom form field', link: '/guide/custom-form-fields.md' } ] }, diff --git a/docs/guide/building-entity-list.md b/docs/guide/building-entity-list.md index 1b736548d..4387864c7 100644 --- a/docs/guide/building-entity-list.md +++ b/docs/guide/building-entity-list.md @@ -229,8 +229,6 @@ Here is the full list of available methods: - `configureDefaultSort(string $sortBy, string $sortDir = "asc")`: `EntityListQueryParams $queryParams` will be filled with this default value (see above) -- `configureMultiformAttribute(string $attribute)`: :warning: This feature has been deprecated in version 9.6.0 and was replaced by the [Entity Map](#entity-map) feature. You can still access to the [documentation](multiforms.md) for legacy usage. - - `configureEntityMap(string $attribute, EntityListEntities $entities)`: configure an Entity Map to display multiple entities in a single Entity List; [see detailed section](#entity-map) above. - `configurePageAlert(string $template, string $alertLevel = null, string $fieldKey = null, bool $declareTemplateAsPath = false)`: display a dynamic message above the list; [see detailed doc](page-alerts.md) @@ -255,10 +253,6 @@ To go ahead and learn how to add a link in the Sharp side menu, [look here](buil ## Entity Map -::: info -This feature replaces the deprecated Multiforms functionality, which remains available for legacy use in version 9.x but will be removed in 10.x. -::: - The Entity Map lets you display multiple entities within a single Entity List. This makes it possible to link different Show Pages or Forms based on a discriminating attribute. To set it up, declare the Entity Map in the `buildListConfig()` method by using `configureEntityMap()`: diff --git a/docs/guide/entity-class.md b/docs/guide/entity-class.md index 60be6b019..85f130573 100644 --- a/docs/guide/entity-class.md +++ b/docs/guide/entity-class.md @@ -86,12 +86,6 @@ class MyEntity extends SharpEntity When you need to configure a "unique" resource that does not fit into a List / Show schema, like an account or a configuration item, you can use a Single Show or Form. This is a dedicated topic, [documented here](single-show.md). -### Handle Multiforms - -::: info -This feature has been deprecated and was replaced in version 9.6.0 by the [Entity Map](./building-entity-list.md#entity-map) feature. -::: - ## Declare the Entity in Sharp configuration The last step is to declare the entity in Sharp, in your `SharpAppServiceProvider` implementation. diff --git a/docs/guide/form-fields/upload.md b/docs/guide/form-fields/upload.md index 0611fb9ed..31ac7f7ac 100644 --- a/docs/guide/form-fields/upload.md +++ b/docs/guide/form-fields/upload.md @@ -89,10 +89,6 @@ When a crop ratio is set, any uploaded picture will be auto-cropped (centered). The second argument, `$croppableFileTypes`, provide a way to limit the crop configuration to a list of image files extensions. For instance, it can be useful to define a crop for jpg and png, but not for gif because it will destroy animation. -### `setImageCompactThumbnail(bool $compactThumbnail = true)` - -If true and if the upload has a thumbnail, it is limited to 60px high (to compact in a list item, for instance). - ### `setImageOptimize(bool $imageOptimize = true)` If true, some optimization will be applied on the uploaded images (in order to reduce files weight). It relies on spatie's [laravel-image-optimizer](https://github.com/spatie/laravel-image-optimizer). Please note that you will need some of these packages on your system: diff --git a/docs/guide/multiforms.md b/docs/guide/multiforms.md deleted file mode 100644 index 12698f049..000000000 --- a/docs/guide/multiforms.md +++ /dev/null @@ -1,79 +0,0 @@ -# Multi-Forms (deprecated) - -::: warning -Multi-Forms is a feature that has been deprecated in version 9.6.0 and was replaced by the [Entity Map](./building-entity-list.md#entity-map) feature. -::: - -Let's say you want to handle different variants for an entity in one Entity List. - -For instance, maybe you want to display sold cars on an Entity List: easy enough, you create a `Car` entity, list and form. But you want to handle different form fields for cars with an internal combustion engine and those with an electric engine; you can of course use a form and [conditional display](building-form.md#conditional-display) to achieve this, but in a case where there are many differences, the best option may be to split the Entity in two (or more) Forms. That's Multi-Form. - -## Write the Form classes - -Following up the car example, we would write two Form classes: `CombustionCarForm` and `ElectricCarForm`, maybe. They are regular `SharpForm` classes, as [described here](building-form.md). - -::: tip -Note that You'll probably be able to regroup some common code in a trait or by inheritance: it's up to you. -::: - -## Configuration - -Once the classes are written, you must declare the forms in the entity class: - -```php -class CarEntity extends SharpEntity -{ - protected ?string $list = CarList::class; - protected string $label = 'Car'; - - public function getMultiforms(): array - { - return [ - 'combustion' => [\App\Sharp\CombustionCarForm::class, 'Combustion car'], - 'electric' => [\App\Sharp\ElectricCarForm::class, 'Electric car'], - ]; - } -} -``` - -The expected return of the `getMultiforms()` method is an array with: -- the subentity key as key: this is the value of the split attribute, to disambiguate each type (see below), -- and, as value, an array with the Form class and the subentity label. - -At this stage, you need only one more thing: configure the Entity List to handle Multi-Form. - -## The Entity List - -Now we want to "merge" our Car entity in the Entity List, and allow the user to create or edit either a combustion or an electric car. With the configuration added to the entity class, at the previous step, we already have a dropdown button replacing the "New" button, each value leading to the right Form. - -You must configure an instance attribute to disambiguate each type: each instance must have his attribute valuated either with "electric" or "combustion", in our example. - -You declare this attribute in the Entity List `buildListConfig()` method: - -```php -class CarList extends SharpEntityList -{ - // [...] - function buildListConfig(): void - { - $this->configureMultiformAttribute('engine'); - } -} -``` - -Here, the `engine` attribute must be filled for each Car instance. So how you do that? Obviously, the first way is to keep the same attribute you use in your database: in many cases, you already have this `engine` value in a column. If not, or if the value is something less readable (an ID for instance), use a [custom transformer](how-to-transform-data.md): - -```php -class CarList extends SharpEntityList -{ - // [...] - function getListData(): array - { - return $this - ->setCustomTransformer('engine', function($value, Car $car) { - return $car->motor === 'EV' ? 'electric' : 'combustion'; - }) - ->transform(Car::get()); - } -} -``` diff --git a/docs/guide/upgrade.md b/docs/guide/upgrade.md index c1f643f51..83d5e7545 100644 --- a/docs/guide/upgrade.md +++ b/docs/guide/upgrade.md @@ -4,3 +4,94 @@ You should update the following dependencies in your `composer.json` file: - `inertiajs/inertia-laravel` to `^3.0` (cf. https://inertiajs.com/docs/v3/getting-started/upgrade-guide) + +## Deprecated methods + +### Forms + +#### Upload `setImageCompactThumbnail()` has not impact and can be removed +```php +\Code16\Sharp\Form\Fields\SharpFormUploadField::make('upload') + ->setImageCompactThumbnail() // [!code --] +``` + +## Removed methods + +Several features and methods that were deprecated in Sharp 9.0 have been removed to clean up the codebase. + +### General +- The `currentSharpRequest()` helper and its associated `CurrentSharpRequest` class were removed. Use `sharp()->context()` instead (cf. [Context](context)). +- The `SharpAuthenticationCheckHandler` interface was removed. Use the `viewSharp` Gate instead. +- The `withSharpCurrentBreadcrumb()` method in `SharpAssertions` was removed. Use `withSharpBreadcrumb()` instead. +- Removal of "multi-forms". Replace all `SharpEntity::getMultiforms()` implementations to `SharpEntityList::configureEntityMap()` instead (cf. [Building entity list](building-entity-list#entity-map)). +- Smart handling of legacy fontaweome icons class has been removed. Tou must convert all `fa-` occurences to `fas-*`, `far-*`, `fab-*`. + +### Configuration +- The legacy configuration handling based on the `sharp.php` config file was removed. You must now use a `SharpAppServiceProvider` with a `SharpConfigBuilder`. +- `SharpConfigBuilder::addEntity()` has been removed in favor of `SharpConfigBuilder::declareEntity()`. + +### Forms +- The legacy `$formValidatorClass` property handling in `SharpForm` was removed. Implement the `SharpForm::rules()` and `SharpForm::messages()` methods instead (cf. [Building form](building-form#input-validation)). Along with this removal, the following classes have been removed: + - `\Code16\Sharp\Form\Validator\SharpFormRequest` + - `\Code16\Sharp\Form\Validator\SharpValidator` + - `\Code16\Sharp\Http\Middleware\Api\BindSharpValidationResolver` +- In `SharpFormUploadField`, the following deprecated methods were removed: +```php +\Code16\Sharp\Form\Fields\SharpFormUploadField::make('upload') + ->setCropRatio() // [!code --] + ->setImageCropRatio() // [!code ++] + + ->shouldOptimizeImage() // [!code --] + ->setImageOptimize() // [!code ++] + + ->setTransformable() // [!code --] + ->setImageTransformable() // [!code ++] + + ->setFileFilterImages() // [!code --] + ->setImageOnly() // [!code ++] + + ->setFileFilter() // [!code --] + ->setAllowedExtensions() // [!code ++] +``` +- The `FormLayoutColum::withSingleField()` & `ShowLayoutColum::withSingleField()` method was removed. Use `withField()` or `withListField()` instead. +- `SharpFormDateField::setDisplayFormat()` has been removed +- `SharpFormAutocompleteField` was removed. Migrate to the following + - `SharpFormAutocompleteField::make('key', 'local')` to `SharpFormAutocompleteLocalField::make('key')` + - `SharpFormAutocompleteField::make('key', 'remote')` to `SharpFormAutocompleteRemoteField::make('key')` + +### Entity Lists +- The `setWidthOnSmallScreens()` and `setWidthOnSmallScreensFill()` methods in `EntityListField` were removed as they are no longer used in the new front-end table UI. +- The `configureMultiformAttribute()` method in `SharpEntityList` was removed. Use `configureEntityMap()` instead. + +### Show +- The `configureMultiformAttribute()` method in `SharpShow` was removed. It's not used by sharp. + +### Renamed classes + +The following classes have been renamed / moved: + +```php +use \Code16\Sharp\EntityList\Filters\EntityListCheckFilter; // [!code --] +use \Code16\Sharp\Utils\Filters\CheckFilter; // [!code --] +use \Code16\Sharp\Filters\CheckFilter; // [!code ++] + +use \Code16\Sharp\EntityList\Filters\EntityListDateRangeFilter; // [!code --] +use \Code16\Sharp\Utils\Filters\DateRangeFilter; // [!code --] +use \Code16\Sharp\Filters\DateRangeFilter; // [!code ++] + +use \Code16\Sharp\EntityList\Filters\EntityListDateRangeRequiredFilter; // [!code --] +use \Code16\Sharp\Utils\Filters\DateRangeRequiredFilter; // [!code --] +use \Code16\Sharp\Filters\DateRangeRequiredFilter; // [!code ++] + +use \Code16\Sharp\EntityList\Filters\EntityListSelectFilter; // [!code --] +use \Code16\Sharp\Utils\Filters\SelectFilter; // [!code --] +use \Code16\Sharp\Filters\SelectFilter; // [!code ++] + +use \Code16\Sharp\EntityList\Filters\EntityListSelectMultipleFilter; // [!code --] +use \Code16\Sharp\Utils\Filters\SelectMultipleFilter; // [!code --] +use \Code16\Sharp\Filters\SelectMultipleFilter; // [!code ++] + +use \Code16\Sharp\EntityList\Filters\EntityListSelectRequiredFilter; // [!code --] +use \Code16\Sharp\Utils\Filters\SelectRequiredFilter; // [!code --] +use \Code16\Sharp\Filters\SelectRequiredFilter; // [!code ++] +``` diff --git a/src/Auth/SharpAuthenticationCheckHandler.php b/src/Auth/SharpAuthenticationCheckHandler.php deleted file mode 100644 index cf45e50eb..000000000 --- a/src/Auth/SharpAuthenticationCheckHandler.php +++ /dev/null @@ -1,10 +0,0 @@ -config['entities'][$key] = $entityClass; - $this->config['entity_resolver'] = null; - - return $this; - } - public function declareEntity(string $entityClass): self { if (! is_subclass_of($entityClass, BaseSharpEntity::class)) { diff --git a/src/Config/SharpLegacyConfigBuilder.php b/src/Config/SharpLegacyConfigBuilder.php deleted file mode 100644 index bc4880879..000000000 --- a/src/Config/SharpLegacyConfigBuilder.php +++ /dev/null @@ -1,50 +0,0 @@ -exists($blade)) { - return view($blade)->render(); - } - - return null; - } - - if ($key == 'breadcrumb.display') { - return config('sharp.display_breadcrumb', true); - } - - return config('sharp.'.$key); - } -} diff --git a/src/Data/Form/Fields/FormUploadFieldData.php b/src/Data/Form/Fields/FormUploadFieldData.php index 0219a9ef2..f30664435 100644 --- a/src/Data/Form/Fields/FormUploadFieldData.php +++ b/src/Data/Form/Fields/FormUploadFieldData.php @@ -21,7 +21,6 @@ public function __construct( #[LiteralTypeScriptType('[number, number]')] public ?array $imageCropRatio = null, public bool $imageTransformable = true, - public bool $imageCompactThumbnail = false, public ?bool $imageTransformKeepOriginal = null, /** @var array */ public ?array $imageTransformableFileTypes = null, diff --git a/src/EntityList/Fields/EntityListField.php b/src/EntityList/Fields/EntityListField.php index 7f11b2961..b06820618 100644 --- a/src/EntityList/Fields/EntityListField.php +++ b/src/EntityList/Fields/EntityListField.php @@ -31,21 +31,7 @@ public function setHtml(bool $html = true): self return $this; } - /** - * @deprecated - */ - public function setWidthOnSmallScreens(int $widthOnSmallScreens): self - { - return $this; - } - /** - * @deprecated - */ - public function setWidthOnSmallScreensFill(): self - { - return $this; - } public function toArray(): array { diff --git a/src/EntityList/Fields/EntityListFieldsContainer.php b/src/EntityList/Fields/EntityListFieldsContainer.php index f363456b3..15d2a597d 100644 --- a/src/EntityList/Fields/EntityListFieldsContainer.php +++ b/src/EntityList/Fields/EntityListFieldsContainer.php @@ -29,10 +29,6 @@ public function setWidthOfField(string $fieldKey, ?int $width, int|bool|null $wi if ($widthOnSmallScreens === false) { $field->hideOnSmallScreens(); - } elseif ($widthOnSmallScreens !== null) { - $field->setWidthOnSmallScreens($widthOnSmallScreens); - } else { - $field->setWidthOnSmallScreensFill(); } } diff --git a/src/EntityList/Filters/EntityListCheckFilter.php b/src/EntityList/Filters/EntityListCheckFilter.php deleted file mode 100644 index c49763c4b..000000000 --- a/src/EntityList/Filters/EntityListCheckFilter.php +++ /dev/null @@ -1,10 +0,0 @@ -entityAttribute = $attribute; - - return $this; - } final protected function configureEntityMap(string $attribute, EntityListEntities $entities): self { @@ -300,12 +290,4 @@ abstract protected function buildList(EntityListFieldsContainer $fields): void; * Retrieve all rows data as an array. */ abstract public function getListData(): array|Arrayable; - - /** - * @deprecated no more in use, will be removed in v10.x - */ - final public function configurePaginated(bool $paginated = true): self - { - return $this; - } } diff --git a/src/Form/Fields/SharpFormAutocompleteField.php b/src/Form/Fields/SharpFormAutocompleteField.php deleted file mode 100644 index 5479a3c28..000000000 --- a/src/Form/Fields/SharpFormAutocompleteField.php +++ /dev/null @@ -1,23 +0,0 @@ - SharpFormAutocompleteLocalField::make($key), - 'remote' => SharpFormAutocompleteRemoteField::make($key), - default => throw new SharpInvalidConfigException('Invalid autocomplete mode:'.$mode), - }; - } -} diff --git a/src/Form/Fields/SharpFormDateField.php b/src/Form/Fields/SharpFormDateField.php index cb6e9c077..cb7917b2e 100644 --- a/src/Form/Fields/SharpFormDateField.php +++ b/src/Form/Fields/SharpFormDateField.php @@ -71,14 +71,6 @@ public function setStepTime(int $step): self return $this; } - /** - * @deprecated This feature is not available anymore as the native HTML date input is now used - */ - public function setDisplayFormat(?string $displayFormat = null): self - { - return $this; - } - public function hasDate(): bool { return $this->hasDate; diff --git a/src/Form/Fields/SharpFormUploadField.php b/src/Form/Fields/SharpFormUploadField.php index c75787688..41cb1235d 100644 --- a/src/Form/Fields/SharpFormUploadField.php +++ b/src/Form/Fields/SharpFormUploadField.php @@ -6,6 +6,7 @@ use Code16\Sharp\Form\Fields\Formatters\UploadFormatter; use Code16\Sharp\Utils\Fields\Validation\SharpFileValidation; use Code16\Sharp\Utils\Fields\Validation\SharpImageValidation; +use Illuminate\Validation\Concerns\ValidatesAttributes; use Illuminate\Validation\Rules\Dimensions; class SharpFormUploadField extends SharpFormField @@ -21,7 +22,6 @@ class SharpFormUploadField extends SharpFormField protected ?bool $imageTransformKeepOriginal = null; protected bool $isImageOnly = false; protected ?Dimensions $imageDimensionConstraints = null; - protected bool $imageCompactThumbnail = false; protected bool $imageOptimize = false; protected bool $imageSanitizeSvg = true; protected ?array $imageCropRatio = null; @@ -51,7 +51,7 @@ public function setImageOnly(bool $imageOnly = true): self $this->isImageOnly = $imageOnly; if (! $this->allowedExtensions) { - /** @see \Illuminate\Validation\Concerns\ValidatesAttributes::validateImage() */ + /** @see ValidatesAttributes::validateImage() */ $this->setAllowedExtensions(['.jpg', '.jpeg', '.png', '.gif', '.bmp', '.svg', '.webp']); } @@ -106,10 +106,11 @@ public function isImageSanitizeSvg(): bool return $this->imageSanitizeSvg; } + /** + * @deprecated This method can be removed as it doesn't change anything on the UI + */ public function setImageCompactThumbnail(bool $compactThumbnail = true): self { - $this->imageCompactThumbnail = $compactThumbnail; - return $this; } @@ -210,7 +211,6 @@ protected function validationRules(): array 'imageTransformable' => 'boolean', 'imageTransformableFileTypes' => 'array', 'imageTransformKeepOriginal' => 'boolean', - 'imageCompactThumbnail' => 'boolean', 'validationRule' => 'array', ]; } @@ -222,7 +222,6 @@ public function toArray(): array 'imageTransformable' => $this->imageTransformable, 'imageTransformableFileTypes' => $this->imageTransformableFileTypes, 'imageTransformKeepOriginal' => $this->isImageTransformKeepOriginal(), - 'imageCompactThumbnail' => $this->imageCompactThumbnail, 'maxFileSize' => $this->maxFileSize ?: sharp()->config()->get('uploads.max_file_size'), 'allowedExtensions' => $this->allowedExtensions, 'validationRule' => $this->buildValidationRule(), @@ -255,39 +254,4 @@ private function buildValidationRule(): array return $validationRule->toArray(); } - /** @deprecated use setImageCropRatio() */ - public function setCropRatio(?string $ratio = null, ?array $transformableFileTypes = null): self - { - return $this->setImageCropRatio($ratio, $transformableFileTypes); - } - - /** @deprecated use setImageOptimize() */ - public function shouldOptimizeImage(bool $shouldOptimizeImage = true): self - { - return $this->setImageOptimize($shouldOptimizeImage); - } - - /** @deprecated use setImageCompactThumbnail() */ - public function setCompactThumbnail(bool $compactThumbnail = true): self - { - return $this->setImageCompactThumbnail($compactThumbnail); - } - - /** @deprecated use setImageTransformable() */ - public function setTransformable(bool $transformable = true, ?bool $transformKeepOriginal = null): self - { - return $this->setImageTransformable($transformable, $transformKeepOriginal); - } - - /** @deprecated use setImageOnly() */ - public function setFileFilterImages(): self - { - return $this->setImageOnly(); - } - - /** @deprecated use setAllowExtensions() */ - public function setFileFilter(string|array $fileFilter): self - { - return $this->setAllowedExtensions($fileFilter); - } } diff --git a/src/Form/Layout/HasFieldRows.php b/src/Form/Layout/HasFieldRows.php index fbe72da05..2a5c1b855 100644 --- a/src/Form/Layout/HasFieldRows.php +++ b/src/Form/Layout/HasFieldRows.php @@ -14,15 +14,6 @@ trait HasFieldRows protected array $rows = []; - /** @deprecated use withField() or withListField() instead */ - public function withSingleField(string $fieldKey, ?\Closure $subLayoutCallback = null): static - { - if ($subLayoutCallback) { - return $this->withListField($fieldKey, $subLayoutCallback); - } - - return $this->withField($fieldKey); - } public function withField(string $fieldKey): static { diff --git a/src/Form/Layout/HasModalFormLayout.php b/src/Form/Layout/HasModalFormLayout.php index 377bfd654..535ac9846 100644 --- a/src/Form/Layout/HasModalFormLayout.php +++ b/src/Form/Layout/HasModalFormLayout.php @@ -30,7 +30,7 @@ protected function modalFormLayout(Closure $buildFormLayout): ?array ? $column->withListField($field->key, fn ($layout) => $field ->itemFields() ->each(fn (SharpFormField $itemField) => $layout - ->withSingleField($itemField->key()) + ->withField($itemField->key()) ) ) : $column->withField($field->key) diff --git a/src/Form/SharpForm.php b/src/Form/SharpForm.php index 7e6c6dbf8..a0a317c86 100644 --- a/src/Form/SharpForm.php +++ b/src/Form/SharpForm.php @@ -150,15 +150,6 @@ public function notify(string $title): SharpNotification return new SharpNotification($title); } - /** - * @deprecated use ->validate() or rules() methods instead; will be removed in 10.x - */ - protected function getFormValidatorClass(): ?string - { - return property_exists($this, 'formValidatorClass') - ? $this->formValidatorClass - : null; - } /** * Retrieve a Model for the form and pack all its data as JSON. diff --git a/src/Form/Validator/SharpFormRequest.php b/src/Form/Validator/SharpFormRequest.php deleted file mode 100644 index 337aa2713..000000000 --- a/src/Form/Validator/SharpFormRequest.php +++ /dev/null @@ -1,37 +0,0 @@ -all()) - ->filter(fn ($value) => is_array($value) && array_key_exists('text', $value)) - ->map(function ($value, $key) { - return is_array($value['text']) - ? collect($value['text'])->map(fn ($value, $locale) => "$key.$locale")->toArray() - : $key; - }) - ->flatten() - ->values() - ->toArray(); - - // Replace Editor rules with .text suffix - $newRules = collect($validator->getRules()) - ->mapWithKeys(function ($messages, $key) use ($editorFields) { - if (in_array($key, $editorFields)) { - return ["$key.text" => $messages]; - } - - return [$key => $messages]; - }) - ->toArray(); - - $validator->setRules($newRules); - } -} diff --git a/src/Form/Validator/SharpValidator.php b/src/Form/Validator/SharpValidator.php deleted file mode 100644 index bccf976b6..000000000 --- a/src/Form/Validator/SharpValidator.php +++ /dev/null @@ -1,47 +0,0 @@ -...] structure. - */ -class SharpValidator extends Validator -{ - /** - * @return bool - */ - public function passes() - { - $result = parent::passes(); - - // For all Editor fields, remove the .text in their key (description.text -> description) - $newMessages = collect($this->messages->getMessages()) - ->mapWithKeys(function ($messages, $key) { - if (preg_match('/.*[^\\\\].text.*/', $key)) { - $newKey = Str::replace('.text', '', $key); - - return [ - $newKey => collect($messages) - ->map(fn ($value) => Str::replace($key, $newKey, $value)) - ->toArray(), - ]; - } - - return [ - $key => $messages, - ]; - }) - ->toArray(); - - $this->messages = new MessageBag($newMessages); - - return $result; - } -} diff --git a/src/Http/Context/CurrentSharpRequest.php b/src/Http/Context/CurrentSharpRequest.php deleted file mode 100644 index 79f2ce380..000000000 --- a/src/Http/Context/CurrentSharpRequest.php +++ /dev/null @@ -1,61 +0,0 @@ -context() instead - */ -class CurrentSharpRequest -{ - public function getCurrentBreadcrumbItem(): ?BreadcrumbItem - { - return sharp()->context()->breadcrumb()->currentSegment(); - } - - public function getPreviousShowFromBreadcrumbItems(?string $entityKey = null): ?BreadcrumbItem - { - return sharp()->context()->breadcrumb()->previousShowSegment($entityKey); - } - - public function isEntityList(): bool - { - return sharp()->context()->isEntityList(); - } - - public function isShow(): bool - { - return sharp()->context()->isShow(); - } - - public function isForm(): bool - { - return sharp()->context()->isForm(); - } - - public function isCreation(): bool - { - return sharp()->context()->isCreation(); - } - - public function isUpdate(): bool - { - return sharp()->context()->isUpdate(); - } - - public function entityKey(): ?string - { - return sharp()->context()->entityKey(); - } - - public function instanceId(): ?string - { - return sharp()->context()->instanceId(); - } - - final public function globalFilterFor(string $handlerClassOrKey): array|string|null - { - return sharp()->context()->globalFilterValue($handlerClassOrKey); - } -} diff --git a/src/Http/Context/SharpBreadcrumb.php b/src/Http/Context/SharpBreadcrumb.php index e6a7d3f9d..4fae15e86 100644 --- a/src/Http/Context/SharpBreadcrumb.php +++ b/src/Http/Context/SharpBreadcrumb.php @@ -59,9 +59,9 @@ public function previousSegment(): ?BreadcrumbItem return $this->breadcrumbItems()->reverse()->skip(1)->first(); } - public function previousShowSegment(?string $entityKeyOrClassName = null, ?string $multiformKey = null): ?BreadcrumbItem + public function previousShowSegment(?string $entityKeyOrClassName = null): ?BreadcrumbItem { - return $this->findPreviousSegment('s-show', $entityKeyOrClassName, $multiformKey); + return $this->findPreviousSegment('s-show', $entityKeyOrClassName); } public function previousListSegment(?string $entityKeyOrClassName = null): ?BreadcrumbItem @@ -108,7 +108,7 @@ public function breadcrumbItems(): Collection return $this->breadcrumbItems; } - private function findPreviousSegment(string $type, ?string $entityKeyOrClassName = null, ?string $multiformKey = null): ?BreadcrumbItem + private function findPreviousSegment(string $type, ?string $entityKeyOrClassName = null): ?BreadcrumbItem { $modeNotEquals = false; if ($entityKeyOrClassName && Str::startsWith($entityKeyOrClassName, '!')) { @@ -121,8 +121,8 @@ private function findPreviousSegment(string $type, ?string $entityKeyOrClassName ->filter(fn (BreadcrumbItem $item) => $item->type === $type) ->when($entityKeyOrClassName !== null, fn ($items) => $items ->filter(fn (BreadcrumbItem $breadcrumbItem) => $modeNotEquals - ? ! $breadcrumbItem->entityIs($entityKeyOrClassName, $multiformKey) - : $breadcrumbItem->entityIs($entityKeyOrClassName, $multiformKey) + ? ! $breadcrumbItem->entityIs($entityKeyOrClassName) + : $breadcrumbItem->entityIs($entityKeyOrClassName) ) ) ->first(); @@ -262,7 +262,7 @@ private function resolveEntityLabelForItem(BreadcrumbItem $item, bool $isLeaf): return app(SharpEntityManager::class) ->entityFor($item->key) - ->getLabelOrFail((new EntityKey($item->key))->multiformKey()); + ->getLabelOrFail(); } private function resolveParentShowLabel(BreadcrumbItem $formItem): ?string diff --git a/src/Http/Context/Util/BreadcrumbItem.php b/src/Http/Context/Util/BreadcrumbItem.php index ae4e16cf9..0ebd00549 100644 --- a/src/Http/Context/Util/BreadcrumbItem.php +++ b/src/Http/Context/Util/BreadcrumbItem.php @@ -73,13 +73,12 @@ public function is(BreadcrumbItem $item): bool && $this->instance === $item->instance; } - public function entityIs(string $entityKeyOrClassName, ?string $multiformKey = null): bool + public function entityIs(string $entityKeyOrClassName): bool { $selfKey = new EntityKey($this->key); $resolvedEntityKey = app(SharpEntityManager::class)->entityKeyFor($entityKeyOrClassName); - return $selfKey->baseKey() === $resolvedEntityKey - && (! $multiformKey || $selfKey->multiformKey() === $multiformKey); + return $selfKey->baseKey() === $resolvedEntityKey; } public function entityKey(): string diff --git a/src/Http/Controllers/Api/Commands/ApiEntityListQuickCreationCommandController.php b/src/Http/Controllers/Api/Commands/ApiEntityListQuickCreationCommandController.php index 1ae427d2e..620e5d8fd 100644 --- a/src/Http/Controllers/Api/Commands/ApiEntityListQuickCreationCommandController.php +++ b/src/Http/Controllers/Api/Commands/ApiEntityListQuickCreationCommandController.php @@ -30,14 +30,14 @@ public function create(string $globalFilter, EntityKey $entityKey, EntityKey $fo 403 ); - $form = $this->entityManager->entityFor($formEntityKey)->getFormOrFail($formEntityKey->multiformKey()); + $form = $this->entityManager->entityFor($formEntityKey)->getFormOrFail(); $form->buildFormConfig(); $quickCreationHandler ->setEntityKey($entityKey) ->setFormInstance($form) ->setTitle(__('sharp::breadcrumb.form.create_entity', [ - 'entity' => $entity->getLabelOrFail($entityKey->multiformKey()), + 'entity' => $entity->getLabelOrFail(), ])); $quickCreationHandler->buildCommandConfig(); @@ -60,7 +60,7 @@ public function store(string $globalFilter, EntityKey $entityKey, EntityKey $for 403 ); - $form = $this->entityManager->entityFor($formEntityKey)->getFormOrFail($formEntityKey->multiformKey()); + $form = $this->entityManager->entityFor($formEntityKey)->getFormOrFail(); $form->buildFormConfig(); $quickCreationHandler diff --git a/src/Http/Controllers/Api/DownloadController.php b/src/Http/Controllers/Api/DownloadController.php index b9ad7ca10..73c4b5a1b 100644 --- a/src/Http/Controllers/Api/DownloadController.php +++ b/src/Http/Controllers/Api/DownloadController.php @@ -16,7 +16,7 @@ public function show(string $globalFilter, string $entityKey, ?string $instanceI $this->authorizationManager->check('view', $entityKey, $instanceId); if ( - ($allowedDisks = sharp()->config()->get('downloads.allowed_disks')) !== null // Legacy config + ($allowedDisks = sharp()->config()->get('downloads.allowed_disks')) !== null && $allowedDisks != '*' ) { abort_if(! in_array(request()->get('disk'), $allowedDisks), 403); diff --git a/src/Http/Controllers/Api/HandlesFieldContainer.php b/src/Http/Controllers/Api/HandlesFieldContainer.php index 65ef1e8d5..f90501dd2 100644 --- a/src/Http/Controllers/Api/HandlesFieldContainer.php +++ b/src/Http/Controllers/Api/HandlesFieldContainer.php @@ -59,6 +59,6 @@ private function getFieldContainer(EntityKey $entityKey): SharpFormEditorEmbed|C ); } - return $entity->getFormOrFail($entityKey->multiformKey()); + return $entity->getFormOrFail(); } } diff --git a/src/Http/Controllers/Auth/PasswordResetController.php b/src/Http/Controllers/Auth/PasswordResetController.php index 2404b1e56..b9423fd9f 100644 --- a/src/Http/Controllers/Auth/PasswordResetController.php +++ b/src/Http/Controllers/Auth/PasswordResetController.php @@ -34,7 +34,7 @@ public function store(Request $request): RedirectResponse $defaultResetCallback = function ($user, $password) { $user ->forceFill([ - config('sharp.auth.password_attribute', 'password') => Hash::make($password), + sharp()->config()->get('auth.password_attribute') => Hash::make($password), 'remember_token' => Str::random(60), ]) ->save(); diff --git a/src/Http/Controllers/EntityListController.php b/src/Http/Controllers/EntityListController.php index 2e36951b6..c8108d2ea 100644 --- a/src/Http/Controllers/EntityListController.php +++ b/src/Http/Controllers/EntityListController.php @@ -78,10 +78,9 @@ private function getEntitiesDataForEntityList(string $entityKey, SharpEntityList return null; } - $forms = $this->entityManager->entityFor($entityKey)->getMultiforms(); $entities = $list->getEntities()?->all(); - if (! $forms && ! $entities) { + if (! $entities) { throw new SharpInvalidConfigException( 'The list for the entity ['.$entityKey.'] defines a sub-entity attribute [' .$list->getEntityAttribute() @@ -89,23 +88,6 @@ private function getEntitiesDataForEntityList(string $entityKey, SharpEntityList ); } - if ($forms) { - return collect($forms) - ->map(fn ($value, $key) => [ - 'key' => $key, - 'entityKey' => EntityKey::multiform(baseKey: $entityKey, multiformKey: $key), - 'label' => is_array($value) && count($value) > 1 ? $value[1] : $key, - 'icon' => null, - 'formCreateUrl' => route('code16.sharp.form.create', [ - 'parentUri' => sharp()->context()->breadcrumb()->getCurrentPath(), - 'entityKey' => EntityKey::multiform(baseKey: $entityKey, multiformKey: $key), - ]), - ]) - ->whereNotNull('label') - ->values() - ->all(); - } - return collect($entities) ->map(function (EntityListEntity $listEntity, $key) { $entity = $listEntity->getEntity(); diff --git a/src/Http/Controllers/FormController.php b/src/Http/Controllers/FormController.php index 0d45d1972..5243f89d7 100644 --- a/src/Http/Controllers/FormController.php +++ b/src/Http/Controllers/FormController.php @@ -26,7 +26,7 @@ public function create(string $globalFilter, string $parentUri, EntityKey $entit { $entity = $this->entityManager->entityFor($entityKey); - $form = $entity->getFormOrFail($entityKey->multiformKey()); + $form = $entity->getFormOrFail(); if ($form instanceof SharpSingleForm) { // There is no creation in SingleForms @@ -45,7 +45,7 @@ public function create(string $globalFilter, string $parentUri, EntityKey $entit 'form' => FormData::from([ ...$this->buildFormData($form, $formData, $entityKey), 'title' => $form->getCreateTitle() ?: trans('sharp::breadcrumb.form.create_entity', [ - 'entity' => $entity->getLabelOrFail($entityKey->multiformKey()), + 'entity' => $entity->getLabelOrFail(), ]), ]), 'breadcrumb' => BreadcrumbData::from([ @@ -70,7 +70,7 @@ public function edit(string $globalFilter, string $parentUri, EntityKey $entityK $instanceId ); - $form = $entity->getFormOrFail($entityKey->multiformKey()); + $form = $entity->getFormOrFail(); abort_if( (! $instanceId && ! $form instanceof SharpSingleForm) @@ -92,7 +92,7 @@ public function edit(string $globalFilter, string $parentUri, EntityKey $entityK $titleEntityLabel ??= sharp() ->context() ->breadcrumb() - ->getParentShowCachedBreadcrumbLabel() ?: $entity->getLabelOrFail($entityKey->multiformKey()); + ->getParentShowCachedBreadcrumbLabel() ?: $entity->getLabelOrFail(); if (app()->environment('testing')) { Inertia::share('_rawData', $formData); @@ -128,7 +128,7 @@ public function update(string $globalFilter, string $parentUri, EntityKey $entit $form = $this->entityManager ->entityFor($entityKey) - ->getFormOrFail($entityKey->multiformKey()); + ->getFormOrFail(); abort_if( (! $instanceId && ! $form instanceof SharpSingleForm) @@ -154,7 +154,7 @@ public function store(string $globalFilter, string $parentUri, EntityKey $entity { $form = $this->entityManager ->entityFor($entityKey) - ->getFormOrFail($entityKey->multiformKey()); + ->getFormOrFail(); if ($form instanceof SharpSingleForm) { // There is no creation in SingleForms diff --git a/src/Http/Controllers/HandlesEntityListItems.php b/src/Http/Controllers/HandlesEntityListItems.php index 4c929c699..ae08681bd 100644 --- a/src/Http/Controllers/HandlesEntityListItems.php +++ b/src/Http/Controllers/HandlesEntityListItems.php @@ -41,10 +41,6 @@ private function getItemEntityKey(array $item, string $entityKey, SharpEntity $e : null; if ($itemEntityAttributeValue) { - if (count($entity->getMultiforms()) > 0) { - return EntityKey::multiform(baseKey: $entityKey, multiformKey: $itemEntityAttributeValue); - } - if (! $listEntity = ($list->getEntities()->find($itemEntityAttributeValue))) { throw new SharpInvalidEntityKeyException( sprintf('The sub-entity [%s] for the entity-list [%s] was not found.', $itemEntityAttributeValue, get_class($list)) @@ -78,9 +74,7 @@ private function getItemUrl(array $item, string $entityKey, SharpEntity $entity, 'instanceId' => $item[$list->getInstanceIdAttribute()], ]); } - if ($itemEntity->hasForm() - || $itemEntityKey->multiformKey() && isset($entity->getMultiforms()[$itemEntityKey->multiformKey()]) - ) { + if ($itemEntity->hasForm()) { return route('code16.sharp.form.edit', [ 'parentUri' => $breadcrumb->getCurrentPath(), 'entityKey' => $itemEntityKey, diff --git a/src/Http/Controllers/ShowController.php b/src/Http/Controllers/ShowController.php index 6ce12757d..3ceb85ed7 100644 --- a/src/Http/Controllers/ShowController.php +++ b/src/Http/Controllers/ShowController.php @@ -27,7 +27,7 @@ public function show(string $globalFilter, string $parentUri, EntityKey $entityK $showData = $show->instance($instanceId); $payload = ShowData::from([ - 'title' => $showData[$show->titleAttribute()] ?? $entity->getLabelOrFail($entityKey->multiformKey()), + 'title' => $showData[$show->titleAttribute()] ?? $entity->getLabelOrFail(), 'config' => [ ...$show->showConfig($instanceId), 'formEditUrl' => route('code16.sharp.form.edit', [ diff --git a/src/Http/Controllers/SingleShowController.php b/src/Http/Controllers/SingleShowController.php index d88eb3221..273e77497 100644 --- a/src/Http/Controllers/SingleShowController.php +++ b/src/Http/Controllers/SingleShowController.php @@ -24,7 +24,7 @@ public function show(string $globalFilter, EntityKey $entityKey) $showData = $show->instance(null); $payload = ShowData::from([ - 'title' => $showData[$show->titleAttribute()] ?? $entity->getLabelOrFail($entityKey->multiformKey()), + 'title' => $showData[$show->titleAttribute()] ?? $entity->getLabelOrFail(), 'config' => [ ...$show->showConfig(null), 'formEditUrl' => route('code16.sharp.form.edit', [ diff --git a/src/Http/Middleware/Api/BindSharpValidationResolver.php b/src/Http/Middleware/Api/BindSharpValidationResolver.php deleted file mode 100644 index a7c832198..000000000 --- a/src/Http/Middleware/Api/BindSharpValidationResolver.php +++ /dev/null @@ -1,18 +0,0 @@ -validator->resolver(function ($translator, $data, $rules, $messages) { - return new SharpValidator($translator, $data, $rules, $messages); - }); - - return $next($request); - } -} diff --git a/src/Http/Middleware/SharpAuthenticate.php b/src/Http/Middleware/SharpAuthenticate.php index 917ddefe3..de8aa8065 100644 --- a/src/Http/Middleware/SharpAuthenticate.php +++ b/src/Http/Middleware/SharpAuthenticate.php @@ -24,10 +24,6 @@ public function handle($request, Closure $next, ...$guards) if (! Gate::allows('viewSharp')) { $this->unauthenticated($request, $guards); } - } elseif ($checkHandler = config('sharp.auth.check_handler')) { - if (! instanciate($checkHandler)->check(auth()->guard($guards[0] ?? null)->user())) { - $this->unauthenticated($request, $guards); - } } return $next($request); diff --git a/src/Http/Middleware/SharpRedirectIfAuthenticated.php b/src/Http/Middleware/SharpRedirectIfAuthenticated.php index d32578167..6d89ff6be 100644 --- a/src/Http/Middleware/SharpRedirectIfAuthenticated.php +++ b/src/Http/Middleware/SharpRedirectIfAuthenticated.php @@ -25,12 +25,6 @@ protected function checkSharpUserAuthenticated($guard) return Gate::allows('viewSharp'); } - // Legacy check: - if ($checkHandler = config('sharp.auth.check_handler')) { - return instanciate($checkHandler) - ->check(auth()->guard($guard)->user()); - } - return true; } diff --git a/src/SharpInternalServiceProvider.php b/src/SharpInternalServiceProvider.php index 6cec39cb6..d71a0b78b 100644 --- a/src/SharpInternalServiceProvider.php +++ b/src/SharpInternalServiceProvider.php @@ -11,7 +11,6 @@ use Code16\Sharp\Auth\TwoFactor\Sharp2faHandler; use Code16\Sharp\Auth\TwoFactor\Sharp2faNotificationHandler; use Code16\Sharp\Config\SharpConfigBuilder; -use Code16\Sharp\Config\SharpLegacyConfigBuilder; use Code16\Sharp\Console\DashboardMakeCommand; use Code16\Sharp\Console\EntityCommandMakeCommand; use Code16\Sharp\Console\EntityListFilterMakeCommand; @@ -31,7 +30,6 @@ use Code16\Sharp\Exceptions\SharpTokenMismatchException; use Code16\Sharp\Form\Eloquent\Uploads\Migration\CreateUploadsMigration; use Code16\Sharp\Form\Eloquent\Uploads\Thumbnails\SharpImageManager; -use Code16\Sharp\Http\Context\CurrentSharpRequest; use Code16\Sharp\Http\Middleware\AddLinkHeadersForPreloadedRequests; use Code16\Sharp\Http\Middleware\SharpAuthenticate; use Code16\Sharp\Http\Middleware\SharpRedirectIfAuthenticated; @@ -89,11 +87,6 @@ public function boot() $this->registerViewExceptionMapper(); - if (config('sharp.locale')) { - setlocale(LC_ALL, config('sharp.locale')); - Carbon::setLocale(config('sharp.locale')); - } - $this->configureOctane(); Event::subscribe(PasskeyEventSubscriber::class); @@ -102,16 +95,10 @@ public function boot() public function register() { $this->app->singleton(SharpAuthorizationManager::class); - $this->app->singleton(CurrentSharpRequest::class); $this->app->singleton(SharpMenuManager::class); $this->app->singleton(SharpUploadManager::class); $this->app->singleton(SharpUtil::class); - $this->app->singleton( - SharpConfigBuilder::class, - fn () => file_exists(config_path('sharp.php')) - ? new SharpLegacyConfigBuilder() - : new SharpConfigBuilder() - ); + $this->app->singleton(SharpConfigBuilder::class, fn () => new SharpConfigBuilder()); $this->app->singleton(SharpImageManager::class); $this->app->singleton(AddLinkHeadersForPreloadedRequests::class); diff --git a/src/Show/SharpShow.php b/src/Show/SharpShow.php index 8e6b56202..74405f66a 100644 --- a/src/Show/SharpShow.php +++ b/src/Show/SharpShow.php @@ -77,14 +77,6 @@ public function showConfig(mixed $instanceId, array $config = []): array }); } - /** - * @deprecated to be deleted, no more useful - */ - final protected function configureMultiformAttribute(string $attribute): self - { - return $this; - } - final protected function configurePageTitleAttribute(string $attribute, bool $localized = false): self { $this->pageTitleField = SharpShowTextField::make($attribute)->setLocalized($localized); diff --git a/src/Utils/Entities/SharpEntity.php b/src/Utils/Entities/SharpEntity.php index 3213cb963..ac1951fa2 100644 --- a/src/Utils/Entities/SharpEntity.php +++ b/src/Utils/Entities/SharpEntity.php @@ -47,20 +47,8 @@ final public function hasForm(): bool return $this->getForm() !== null; } - final public function getFormOrFail(?string $multiformKey = null): SharpForm + final public function getFormOrFail(): SharpForm { - if ($multiformKey) { - if (count($this->getMultiforms())) { - if (! $form = ($this->getMultiforms()[$multiformKey][0] ?? null)) { - throw new SharpInvalidEntityKeyException( - sprintf('The subform for the entity [%s:%s] was not found.', get_class($this), $multiformKey) - ); - } - - return instanciate($form); - } - } - if (! $form = $this->getForm()) { throw new SharpInvalidEntityKeyException( sprintf('The form for the entity [%s] was not found.', get_class($this)) @@ -70,19 +58,9 @@ final public function getFormOrFail(?string $multiformKey = null): SharpForm return instanciate($form); } - final public function getLabelOrFail(?string $multiformKey = null): string + final public function getLabelOrFail(): string { - $label = $multiformKey - ? $this->getMultiforms()[$multiformKey][1] ?? null - : $this->getLabel(); - - if ($label === null) { - throw new SharpInvalidEntityKeyException( - sprintf('The label of the subform for the entity [%s:%s] was not found.', get_class($this), $multiformKey) - ); - } - - return $label; + return $this->getLabel(); } final public function isActionProhibited(string $action): bool @@ -120,13 +98,4 @@ protected function getForm(): ?SharpForm { return $this->form ? app($this->form) : null; } - - /** - * @deprecated - * @see SharpEntityList::configureEntityMap() - */ - public function getMultiforms(): array - { - return []; - } } diff --git a/src/Utils/Entities/SharpEntityManager.php b/src/Utils/Entities/SharpEntityManager.php index 286b2e128..c06592d94 100644 --- a/src/Utils/Entities/SharpEntityManager.php +++ b/src/Utils/Entities/SharpEntityManager.php @@ -14,10 +14,6 @@ public function entityFor(string $entityKey): SharpEntity|SharpDashboardEntity if (count(sharp()->config()->get('entities')) > 0) { $entityClass = sharp()->config()->get('entities.'.$entityKey); - if (! $entityClass) { - // Legacy dashboard configuration (to be removed in 10.x) - $entityClass = sharp()->config()->get('dashboards.'.$entityKey); - } } elseif ($sharpEntityResolver = sharp()->config()->get('entity_resolver')) { // A custom SharpEntityResolver is used if (! app()->bound(get_class($sharpEntityResolver))) { diff --git a/src/Utils/Entities/ValueObjects/EntityKey.php b/src/Utils/Entities/ValueObjects/EntityKey.php index 035e232a8..ee0954ea9 100644 --- a/src/Utils/Entities/ValueObjects/EntityKey.php +++ b/src/Utils/Entities/ValueObjects/EntityKey.php @@ -15,11 +15,6 @@ public function __construct( protected ?string $key = null ) {} - public static function multiform(string $baseKey, ?string $multiformKey): static - { - return new static($multiformKey ? "$baseKey:$multiformKey" : $baseKey); - } - public function baseKey(): string { return str_contains($this->key, ':') @@ -27,13 +22,6 @@ public function baseKey(): string : $this->key; } - public function multiformKey(): ?string - { - return str_contains($this->key, ':') - ? Str::after($this->key, ':') - : null; - } - public function getRouteKey() { return $this->key; diff --git a/src/Utils/Fields/HandleFormFields.php b/src/Utils/Fields/HandleFormFields.php index a1bb3a8ed..a8abfb7c8 100644 --- a/src/Utils/Fields/HandleFormFields.php +++ b/src/Utils/Fields/HandleFormFields.php @@ -15,23 +15,14 @@ trait HandleFormFields */ final public function formatAndValidateRequestData(array $data, ?string $instanceId = null): array { - $legacyValidation = property_exists($this, 'formValidatorClass'); - - if ($legacyValidation) { - // Legacy support (v8 and below): first validate, then format - app($this->formValidatorClass); - } - $formattedData = $this->formatRequestData($data, $instanceId); - if (! $legacyValidation) { - if (method_exists($this, 'rules')) { - $this->validate( - $formattedData, - $this->rules($formattedData), - method_exists($this, 'messages') ? $this->messages($formattedData) : [] - ); - } + if (method_exists($this, 'rules')) { + $this->validate( + $formattedData, + $this->rules($formattedData), + method_exists($this, 'messages') ? $this->messages($formattedData) : [] + ); } return $formattedData; diff --git a/src/Utils/Filters/CheckFilter.php b/src/Utils/Filters/CheckFilter.php deleted file mode 100644 index f7ffd02ba..000000000 --- a/src/Utils/Filters/CheckFilter.php +++ /dev/null @@ -1,8 +0,0 @@ - $resolvedBladeIconName, - 'svg' => svg($resolvedBladeIconName)->toHtml(), - ]; - } catch (SvgNotFound $e) { - if (! str_contains($e->getMessage(), 'fontawesome')) { - return null; // for legacy "fa-" class names we don't want to throw (if owenvoke/blade-fontawesome is not installed) - } - throw $e; - } - } - /** * @throws SvgNotFound */ @@ -48,10 +15,6 @@ public function iconToArray(?string $icon): ?array return null; } - if ($nameFromLegacy = $this->resolveLegacyFontAwesomeBladeIconName($icon)) { - return $this->legacyIconToArray($nameFromLegacy); - } - return [ 'name' => $icon, 'svg' => svg($icon)->toHtml(), diff --git a/src/Utils/Testing/SharpAssertions.php b/src/Utils/Testing/SharpAssertions.php index f5d8c4897..f9a4adcd1 100644 --- a/src/Utils/Testing/SharpAssertions.php +++ b/src/Utils/Testing/SharpAssertions.php @@ -46,23 +46,6 @@ public function sharpDashboard(string $entityClassNameOrKey): PendingDashboard return new PendingDashboard($this, $entityClassNameOrKey); } - /** - * @deprecated use withSharpBreadcrumb() instead - */ - public function withSharpCurrentBreadcrumb(...$breadcrumb): static - { - $this->breadcrumbBuilder = new BreadcrumbBuilder(); - - collect($breadcrumb) - ->each(fn (array $segment) => match ($segment[0]) { - 'list' => $this->breadcrumbBuilder->appendEntityList($segment[1]), - 'show' => (count($segment) == 2) - ? $this->breadcrumbBuilder->appendSingleShowPage($segment[1]) - : $this->breadcrumbBuilder->appendShowPage($segment[1], $segment[2]), - }); - - return $this; - } /** * @param (\Closure(BreadcrumbBuilder): BreadcrumbBuilder) $callback diff --git a/src/sharp_helper.php b/src/sharp_helper.php index 77ebd577e..3aff00f1b 100644 --- a/src/sharp_helper.php +++ b/src/sharp_helper.php @@ -5,14 +5,6 @@ function sharp(): \Code16\Sharp\Utils\SharpUtil return app(\Code16\Sharp\Utils\SharpUtil::class); } -/** - * @deprecated use sharp()->context() instead - */ -function currentSharpRequest(): \Code16\Sharp\Http\Context\CurrentSharpRequest -{ - return app(\Code16\Sharp\Http\Context\CurrentSharpRequest::class); -} - function instanciate($class) { return is_string($class) ? app($class) : value($class); diff --git a/tests/Fixtures/Entities/PersonEntity.php b/tests/Fixtures/Entities/PersonEntity.php index 41b78a3f5..517bd4f29 100644 --- a/tests/Fixtures/Entities/PersonEntity.php +++ b/tests/Fixtures/Entities/PersonEntity.php @@ -14,9 +14,6 @@ class PersonEntity extends SharpEntity { public static string $entityKey = 'person'; - public ?string $validatorForTest = null; - public array $multiformValidatorsForTest = []; - public ?array $fakeMultiforms = null; protected string $label = 'person'; protected ?string $list = PersonList::class; protected ?SharpEntityList $fakeList; @@ -70,24 +67,6 @@ protected function getList(): ?SharpEntityList return isset($this->fakeList) ? clone $this->fakeList : parent::getList(); } - public function setValidator(string $validatorClass, ?string $subentity = null): self - { - if (! $subentity) { - $this->validatorForTest = $validatorClass; - } else { - $this->multiformValidatorsForTest[$subentity] = $validatorClass; - } - - return $this; - } - - public function setMultiforms(array $multiform): self - { - $this->fakeMultiforms = $multiform; - - return $this; - } - public function setLabel(string $label): self { $this->label = $label; @@ -95,11 +74,6 @@ public function setLabel(string $label): self return $this; } - public function getMultiforms(): array - { - return $this->fakeMultiforms ?? parent::getMultiforms(); - } - public function setPolicy(SharpEntityPolicy $policy): self { $this->fakePolicy = $policy; diff --git a/tests/Fixtures/Sharp/PersonLegacyValidator.php b/tests/Fixtures/Sharp/PersonLegacyValidator.php deleted file mode 100644 index 6b027c486..000000000 --- a/tests/Fixtures/Sharp/PersonLegacyValidator.php +++ /dev/null @@ -1,15 +0,0 @@ - ['required', 'string', 'max:150'], - ]; - } -} diff --git a/tests/Http/Api/Commands/ApiEntityListQuickCreationCommandControllerTest.php b/tests/Http/Api/Commands/ApiEntityListQuickCreationCommandControllerTest.php index 79ab781b5..7b394d258 100644 --- a/tests/Http/Api/Commands/ApiEntityListQuickCreationCommandControllerTest.php +++ b/tests/Http/Api/Commands/ApiEntityListQuickCreationCommandControllerTest.php @@ -286,9 +286,9 @@ public function update($id, array $data) }); it('returns a link action on a quick creation in an EEL case command with a form with configureDisplayShowPageAfterCreation', function () { - sharp()->config()->addEntity('colleague', PersonEntity::class); + sharp()->config()->declareEntity(PersonEntity::class); - fakeListFor('colleague', new class() extends PersonList + fakeListFor(PersonEntity::class, new class() extends PersonList { public function buildListConfig(): void { @@ -296,7 +296,7 @@ public function buildListConfig(): void } }); - fakeFormFor('colleague', new class() extends PersonForm + fakeFormFor(PersonEntity::class, new class() extends PersonForm { public function buildFormConfig(): void { @@ -313,8 +313,8 @@ public function update($id, array $data) $this ->postJson( route('code16.sharp.api.list.command.quick-creation-form.create', [ - 'entityKey' => 'colleague', - 'formEntityKey' => 'colleague', + 'entityKey' => 'person', + 'formEntityKey' => 'person', ]), ['data' => ['name' => 'Marie Curie']], headers: [ @@ -324,7 +324,7 @@ public function update($id, array $data) ->assertOk() ->assertJson([ 'action' => 'link', - 'link' => url('/sharp/root/s-list/person/s-show/person/1/s-show/colleague/4'), + 'link' => url('/sharp/root/s-list/person/s-show/person/1/s-show/person/4'), ]); }); diff --git a/tests/Http/Auth/AuthorizationsTest.php b/tests/Http/Auth/AuthorizationsTest.php index 4c3d54896..27ac9b05e 100644 --- a/tests/Http/Auth/AuthorizationsTest.php +++ b/tests/Http/Auth/AuthorizationsTest.php @@ -104,21 +104,23 @@ }); it('always disallow create and delete actions for a single show', function () { - sharp()->config()->addEntity('single_person', SinglePersonEntity::class); + sharp()->config()->declareEntity(SinglePersonEntity::class); + app(SharpEntityManager::class) - ->entityFor('single_person') + ->entityFor('single-person') ->setProhibitedActions([]); - fakeShowFor('single_person', new class() extends FakeSharpSingleShow + + fakeShowFor(SinglePersonEntity::class, new class() extends FakeSharpSingleShow { public function findSingle(): array { return []; } }); - fakePolicyFor('single_person', new class() extends SharpEntityPolicy {}); + fakePolicyFor(SinglePersonEntity::class, new class() extends SharpEntityPolicy {}); $this - ->get('/sharp/root/s-show/single_person') + ->get('/sharp/root/s-show/single-person') ->assertOk() ->assertInertia(fn (AssertableJson $json) => $json ->where('show.authorizations', [ @@ -222,43 +224,6 @@ public function getListData(): array|Arrayable ); }); -it('checks the main entity prohibited actions in case of a sub entity', function () { - app(SharpEntityManager::class) - ->entityFor('person') - ->setMultiforms([ - 'big' => [FakeSharpForm::class, 'Big'], - ]) - ->setProhibitedActions(['delete']); - - $this->get('/sharp/root/s-list/person/s-form/person:big')->assertOk(); - $this->post('/sharp/root/s-list/person/s-form/person:big')->assertRedirect(); - $this->get('/sharp/root/s-list/person/s-form/person:big/50')->assertOk(); - $this->post('/sharp/root/s-list/person/s-form/person:big/50')->assertRedirect(); - $this->delete('/sharp/root/s-list/person/s-show/person:big/50')->assertForbidden(); - $this->get(route('code16.sharp.list', 'person'))->assertOk(); -}); - -it('handles custom auth check', function () { - $this->app['config']->set( - 'sharp.auth.check_handler', - fn () => new class() implements SharpAuthenticationCheckHandler - { - public function check($user): bool - { - return $user->name == 'ok'; - } - } - ); - - login(new User(['name' => 'ok'])); - $this->get(route('code16.sharp.list', 'person')) - ->assertOk(); - - login(new User(['name' => 'ko'])); - $this->get(route('code16.sharp.list', 'person')) - ->assertRedirect(route('code16.sharp.login')); -}); - it('checks useSharp Gate', function () { Gate::define('viewSharp', fn ($user) => $user->name === 'ok'); diff --git a/tests/Http/Context/SharpContextTest.php b/tests/Http/Context/SharpContextTest.php index 941947fd4..237b87410 100644 --- a/tests/Http/Context/SharpContextTest.php +++ b/tests/Http/Context/SharpContextTest.php @@ -24,11 +24,9 @@ }); it('allows to get form creation state from request', function () { - // We have to define "child" as a non-single form - app()->bind('child_entity', fn () => new class() extends SharpEntity {}); - sharp()->config()->addEntity('child', 'child_entity'); + sharp()->config()->declareEntity(PersonEntity::class); - $this->fakeBreadcrumbWithUrl('/sharp/root/s-list/person/s-show/person/1/s-form/child'); + $this->fakeBreadcrumbWithUrl('/sharp/root/s-list/person/s-show/person/1/s-form/person'); expect(sharp()->context()) ->isForm()->toBeTrue() @@ -99,21 +97,6 @@ ->previousShowSegment(PersonEntity::class)->instanceId()->toEqual(42); }); -it('allows to get previous show of a given entity class name & subentity from request', function () { - app(SharpConfigBuilder::class)->declareEntity(PersonEntity::class); - app(SharpEntityManager::class)->entityFor('person')->setMultiforms([ - 'multiform' => [PersonForm::class, 'Multiform'], - ]); - $this->fakeBreadcrumbWithUrl('/sharp/root/s-list/person/s-show/person/31/s-show/person:multiform/42/s-show/child:multiform/84/s-form/child/84'); - - expect(sharp()->context()->breadcrumb()) - ->previousShowSegment()->entityKey()->toBe('child:multiform') - ->previousShowSegment()->instanceId()->toEqual(84) - ->previousShowSegment(PersonEntity::class)->entityKey()->toBe('person:multiform') - ->previousShowSegment(PersonEntity::class)->instanceId()->toEqual(42) - ->previousShowSegment(PersonEntity::class, 'multiform')->entityKey()->toBe('person:multiform') - ->previousShowSegment(PersonEntity::class, 'multiform')->instanceId()->toEqual(42); -}); it('allows to check entity of a segment', function () { app(SharpConfigBuilder::class)->declareEntity(PersonEntity::class); @@ -122,35 +105,9 @@ expect(sharp()->context()->breadcrumb()->currentSegment()->entityIs(PersonEntity::class))->toBeTrue(); expect(sharp()->context()->breadcrumb()->currentSegment()->entityIs('person'))->toBeTrue(); - expect(sharp()->context()->breadcrumb()->currentSegment()->entityIs(PersonEntity::class, 'multiform'))->toBeFalse(); - expect(sharp()->context()->breadcrumb()->currentSegment()->entityIs(SinglePersonEntity::class))->toBeFalse(); - expect(sharp()->context()->breadcrumb()->currentSegment()->entityIs('child'))->toBeFalse(); - expect(sharp()->context()->breadcrumb()->previousShowSegment()->entityIs(PersonEntity::class))->toBeTrue(); - expect(sharp()->context()->breadcrumb()->previousShowSegment()->entityIs(PersonEntity::class, 'multiform'))->toBeFalse(); - expect(sharp()->context()->breadcrumb()->previousShowSegment()->entityIs(SinglePersonEntity::class))->toBeFalse(); - expect(sharp()->context()->breadcrumb()->previousShowSegment()->entityIs('child'))->toBeFalse(); -}); - -it('allows to check entity with subentity of a segment', function () { - app(SharpConfigBuilder::class)->declareEntity(PersonEntity::class); - app(SharpConfigBuilder::class)->declareEntity(SinglePersonEntity::class); - app(SharpEntityManager::class)->entityFor('person')->setMultiforms([ - 'multiform' => [PersonForm::class, 'Multiform'], - ]); - $this->fakeBreadcrumbWithUrl('/sharp/root/s-list/person/s-show/person:multiform/1/s-form/person:multiform/1'); - - expect(sharp()->context()->breadcrumb()->currentSegment()->entityIs(PersonEntity::class))->toBeTrue(); - expect(sharp()->context()->breadcrumb()->currentSegment()->entityIs('person'))->toBeTrue(); - expect(sharp()->context()->breadcrumb()->currentSegment()->entityIs('person', 'multiform'))->toBeTrue(); - expect(sharp()->context()->breadcrumb()->currentSegment()->entityIs(PersonEntity::class, 'multiform'))->toBeTrue(); - expect(sharp()->context()->breadcrumb()->currentSegment()->entityIs(PersonEntity::class, 'other-multiform'))->toBeFalse(); expect(sharp()->context()->breadcrumb()->currentSegment()->entityIs(SinglePersonEntity::class))->toBeFalse(); expect(sharp()->context()->breadcrumb()->currentSegment()->entityIs('child'))->toBeFalse(); expect(sharp()->context()->breadcrumb()->previousShowSegment()->entityIs(PersonEntity::class))->toBeTrue(); - expect(sharp()->context()->breadcrumb()->previousShowSegment()->entityIs('person'))->toBeTrue(); - expect(sharp()->context()->breadcrumb()->previousShowSegment()->entityIs('person', 'multiform'))->toBeTrue(); - expect(sharp()->context()->breadcrumb()->previousShowSegment()->entityIs(PersonEntity::class, 'multiform'))->toBeTrue(); - expect(sharp()->context()->breadcrumb()->previousShowSegment()->entityIs(PersonEntity::class, 'other-multiform'))->toBeFalse(); expect(sharp()->context()->breadcrumb()->previousShowSegment()->entityIs(SinglePersonEntity::class))->toBeFalse(); expect(sharp()->context()->breadcrumb()->previousShowSegment()->entityIs('child'))->toBeFalse(); }); diff --git a/tests/Http/EntityListControllerTest.php b/tests/Http/EntityListControllerTest.php index 674aef088..ef38e586a 100644 --- a/tests/Http/EntityListControllerTest.php +++ b/tests/Http/EntityListControllerTest.php @@ -416,115 +416,6 @@ public function delete($user, $instanceId): bool ); }); -it('gets multiforms if configured', function () { - $this->withoutExceptionHandling(); - fakeListFor('person', new class() extends PersonList - { - public function getListData(): array|Arrayable - { - return [ - ['id' => 1, 'name' => 'Marie Curie', 'nobel' => 'yes'], - ['id' => 2, 'name' => 'Rosalind Franklin', 'nobel' => 'nope'], - ]; - } - - public function buildListConfig(): void - { - $this->configureMultiformAttribute('nobel'); - } - }); - - app(SharpEntityManager::class) - ->entityFor('person') - ->setMultiforms([ - 'yes' => [PersonForm::class, 'With Nobel prize'], - 'nope' => [PersonForm::class, 'No Nobel prize'], - ]); - - $this->get(route('code16.sharp.list', 'person')) - ->assertOk() - ->assertInertia(fn (Assert $page) => $page - ->has('entityList.entities', 2) - ->has('entityList.entities.0', fn (Assert $config) => $config - ->where('key', 'yes') - ->where('entityKey', 'person:yes') - ->where('label', 'With Nobel prize') - ->etc() - ) - ->has('entityList.entities.1', fn (Assert $config) => $config - ->where('key', 'nope') - ->where('entityKey', 'person:nope') - ->where('label', 'No Nobel prize') - - ->etc() - ) - ->has('entityList.data.0', fn (Assert $json) => $json - ->where('_meta.url', route('code16.sharp.show.show', ['parentUri' => 's-list/person', 'entityKey' => 'person:yes', 'instanceId' => 1])) - ->etc() - ) - ->has('entityList.data.1', fn (Assert $json) => $json - ->where('_meta.url', route('code16.sharp.show.show', ['parentUri' => 's-list/person', 'entityKey' => 'person:nope', 'instanceId' => 2])) - ->etc() - ) - ); -}); - -it('gets multiform form url if configured', function () { - $this->withoutExceptionHandling(); - fakeListFor('person', new class() extends PersonList - { - public function getListData(): array|Arrayable - { - return [ - ['id' => 1, 'name' => 'Marie Curie', 'nobel' => 'yes'], - ['id' => 2, 'name' => 'Rosalind Franklin', 'nobel' => 'nope'], - ]; - } - - public function buildListConfig(): void - { - $this->configureMultiformAttribute('nobel'); - } - }); - - app(SharpEntityManager::class) - ->entityFor('person') - ->setShow(null) - ->setMultiforms([ - 'yes' => [PersonForm::class, 'With Nobel prize'], - 'nope' => [PersonForm::class, 'No Nobel prize'], - ]); - - $this->get(route('code16.sharp.list', 'person')) - ->assertOk() - ->assertInertia(fn (Assert $page) => $page - ->has('entityList.data.0', fn (Assert $json) => $json - ->where('_meta.url', route('code16.sharp.form.edit', ['parentUri' => 's-list/person', 'entityKey' => 'person:yes', 'instanceId' => 1])) - ->etc() - ) - ->has('entityList.data.1', fn (Assert $json) => $json - ->where('_meta.url', route('code16.sharp.form.edit', ['parentUri' => 's-list/person', 'entityKey' => 'person:nope', 'instanceId' => 2])) - ->etc() - ) - ); - - app(SharpEntityManager::class) - ->entityFor('person') - ->setForm(null); - - $this->get(route('code16.sharp.list', 'person')) - ->assertOk() - ->assertInertia(fn (Assert $page) => $page - ->has('entityList.data.0', fn (Assert $json) => $json - ->where('_meta.url', route('code16.sharp.form.edit', ['parentUri' => 's-list/person', 'entityKey' => 'person:yes', 'instanceId' => 1])) - ->etc() - ) - ->has('entityList.data.1', fn (Assert $json) => $json - ->where('_meta.url', route('code16.sharp.form.edit', ['parentUri' => 's-list/person', 'entityKey' => 'person:nope', 'instanceId' => 2])) - ->etc() - ) - ); -}); it('get entities if configured', function () { $this->withoutExceptionHandling(); diff --git a/tests/Http/Form/FormControllerTest.php b/tests/Http/Form/FormControllerTest.php index 603297d00..d7cede155 100644 --- a/tests/Http/Form/FormControllerTest.php +++ b/tests/Http/Form/FormControllerTest.php @@ -18,7 +18,6 @@ use Code16\Sharp\Tests\Fixtures\Sharp\PersonForm; use Code16\Sharp\Tests\Fixtures\Sharp\PersonShow; use Code16\Sharp\Tests\Fixtures\Sharp\PersonSingleForm; -use Code16\Sharp\Utils\Entities\SharpEntityManager; use Code16\Sharp\Utils\Fields\FieldsContainer; use Code16\Sharp\Utils\PageAlerts\PageAlert; use Illuminate\Support\Facades\Cache; @@ -391,53 +390,6 @@ public function findSingle(): array ->assertRedirect('/sharp/root/s-show/single-person'); }); -it('gets form data for an instance of a sub entity (multiforms case)', function () { - app(SharpEntityManager::class) - ->entityFor('person') - ->setMultiforms([ - 'nobelized' => [ - new class() extends PersonForm - { - public function find($id): array - { - return [ - 'id' => 1, - 'name' => 'Marie Curie', - 'nobel' => 'nobelized', - ]; - } - }, - 'With Nobel prize', - ], - 'nope' => [ - new class() extends PersonForm - { - public function find($id): array - { - return [ - 'id' => 2, - 'name' => 'Rosalind Franklin', - 'nobel' => 'nope', - ]; - } - }, - 'No Nobel prize', - ], - ]); - - $this->get('/sharp/root/s-list/person/s-form/person:nobelized/1') - ->assertOk() - ->assertInertia(fn (Assert $page) => $page - ->where('form.data.name', 'Marie Curie') - ); - - $this->get('/sharp/root/s-list/person/s-form/person:nope/1') - ->assertOk() - ->assertInertia(fn (Assert $page) => $page - ->where('form.data.name', 'Rosalind Franklin') - ); -}); - it('allows to configure a page alert', function () { $this->withoutExceptionHandling(); @@ -497,25 +449,6 @@ public function find($id): array ); }); -it('allows to use the legacy validation', function () { - fakeFormFor('person', new class() extends PersonForm - { - protected string $formValidatorClass = \Code16\Sharp\Tests\Fixtures\Sharp\PersonLegacyValidator::class; - }); - - $this - ->post('/sharp/root/s-list/person/s-form/person', [ - 'name' => '', - ]) - ->assertSessionHasErrors('name'); - - $this - ->post('/sharp/root/s-list/person/s-form/person/1', [ - 'name' => '', - ]) - ->assertSessionHasErrors('name'); -}); - it('formats form title based on parent show breadcrumb', function () { fakeShowFor('person', new class() extends PersonShow { diff --git a/tests/Unit/Config/SharpLegacyConfigBuilderTest.php b/tests/Unit/Config/SharpLegacyConfigBuilderTest.php deleted file mode 100644 index 5264edf49..000000000 --- a/tests/Unit/Config/SharpLegacyConfigBuilderTest.php +++ /dev/null @@ -1,27 +0,0 @@ -bind(SharpConfigBuilder::class, SharpLegacyConfigBuilder::class); -}); - -it('allows to set and get a config value in legacy form', function () { - config()->set('sharp', [ - 'name' => 'Test project', - 'custom_url_segment' => 'test-sharp', - ]); - - expect(sharp()->config()->get('name'))->toBe('Test project') - ->and(sharp()->config()->get('custom_url_segment'))->toBe('test-sharp'); -}); - -it('allows to set and get an entity resolver in legacy form', function () { - config()->set('sharp', [ - 'entities' => 'SomeEntityResolverClass', - ]); - - expect(sharp()->config()->get('entity_resolver'))->toBe('SomeEntityResolverClass'); -}); diff --git a/tests/Unit/Console/GeneratorTest.php b/tests/Unit/Console/GeneratorTest.php index b05617625..c6c323304 100644 --- a/tests/Unit/Console/GeneratorTest.php +++ b/tests/Unit/Console/GeneratorTest.php @@ -33,24 +33,24 @@ ->assertExitCode(0); // Manually add this new Entity to the Sharp config - app(SharpConfigBuilder::class) - ->addEntity('unit_test_models', '\App\Sharp\Entities\UnitTestModelEntity'); + sharp()->config() + ->declareEntity('\App\Sharp\Entities\UnitTestModelEntity'); $this - ->get(route('code16.sharp.list', ['entityKey' => 'unit_test_models'])) + ->get(route('code16.sharp.list', ['entityKey' => 'unit-test-model'])) ->assertOk(); $this ->get(route('code16.sharp.form.create', [ - 'parentUri' => 's-list/unit_test_models', - 'entityKey' => 'unit_test_models', + 'parentUri' => 's-list/unit-test-model', + 'entityKey' => 'unit-test-model', ])) ->assertOk(); $this ->post(route('code16.sharp.form.store', [ - 'parentUri' => 's-list/unit_test_models', - 'entityKey' => 'unit_test_models', + 'parentUri' => 's-list/unit-test-model', + 'entityKey' => 'unit-test-model', ]), [ 'my_field' => 'Arnaud', ]) @@ -58,7 +58,7 @@ $this->assertDatabaseHas('unit_test_models', ['my_field' => 'Arnaud']); - $this->get(route('code16.sharp.list', ['unit_test_models'])) + $this->get(route('code16.sharp.list', ['entityKey' => 'unit-test-model'])) ->assertOk() ->assertSee('Arnaud'); @@ -66,8 +66,8 @@ $this ->get(route('code16.sharp.show.show', [ - 'parentUri' => 's-list/unit_test_models', - 'entityKey' => 'unit_test_models', + 'parentUri' => 's-list/unit-test-model', + 'entityKey' => 'unit-test-model', 'instanceId' => $unitTestModel->id, ])) ->assertOk() @@ -75,16 +75,16 @@ $this ->get(route('code16.sharp.form.edit', [ - 'parentUri' => 's-list/unit_test_models', - 'entityKey' => 'unit_test_models', + 'parentUri' => 's-list/unit-test-model', + 'entityKey' => 'unit-test-model', 'instanceId' => $unitTestModel->id, ])) ->assertOk(); $this ->post(route('code16.sharp.form.update', [ - 'parentUri' => 's-list/unit_test_models', - 'entityKey' => 'unit_test_models', + 'parentUri' => 's-list/unit-test-model', + 'entityKey' => 'unit-test-model', 'instanceId' => $unitTestModel->id, ]), [ 'my_field' => 'Benoit', @@ -95,8 +95,8 @@ $this ->delete(route('code16.sharp.show.delete', [ - 'parentUri' => 's-list/unit_test_models', - 'entityKey' => 'unit_test_models', + 'parentUri' => 's-list/unit-test-model', + 'entityKey' => 'unit-test-model', 'instanceId' => $unitTestModel->id, ])) ->assertStatus(302); @@ -115,8 +115,8 @@ ->assertExitCode(0); // Manually add this new Entity to the Sharp config - app(SharpConfigBuilder::class) - ->addEntity('settings', '\App\Sharp\Entities\SettingsEntity'); + sharp()->config() + ->declareEntity('\App\Sharp\Entities\SettingsEntity'); $this->get( route('code16.sharp.single-show', [ @@ -151,8 +151,8 @@ ->assertExitCode(0); // Manually add this new Entity to the Sharp config - app(SharpConfigBuilder::class) - ->addEntity('financial', '\App\Sharp\Entities\FinancialEntity'); + sharp()->config() + ->declareEntity('\App\Sharp\Entities\FinancialEntity'); $this->get( route('code16.sharp.dashboard', [ @@ -183,8 +183,8 @@ ->expectsConfirmation('Do you want to automatically declare this Entity in the Sharp configuration?', 'no') ->assertExitCode(0); - app(SharpConfigBuilder::class) - ->addEntity('unit_test_models', '\App\Sharp\Entities\UnitTestModelEntity'); + sharp()->config() + ->declareEntity('\App\Sharp\Entities\UnitTestModelEntity'); // Now generate a command $this->artisan('sharp:generator') @@ -217,8 +217,8 @@ ->expectsConfirmation('Do you want to automatically declare this Entity in the Sharp configuration?', 'no') ->assertExitCode(0); - app(SharpConfigBuilder::class) - ->addEntity('unit_test_models', '\App\Sharp\Entities\UnitTestModelEntity'); + sharp()->config() + ->declareEntity('\App\Sharp\Entities\UnitTestModelEntity'); // Now generate a filter $this->artisan('sharp:generator') @@ -252,8 +252,8 @@ ->expectsConfirmation('Do you want to automatically declare this Entity in the Sharp configuration?', 'no') ->assertExitCode(0); - app(SharpConfigBuilder::class) - ->addEntity('unit_test_models', '\App\Sharp\Entities\UnitTestModelEntity'); + sharp()->config() + ->declareEntity('\App\Sharp\Entities\UnitTestModelEntity'); // Now generate an entity state $this->artisan('sharp:generator') @@ -287,8 +287,8 @@ ->expectsConfirmation('Do you want to automatically declare this Entity in the Sharp configuration?', 'no') ->assertExitCode(0); - app(SharpConfigBuilder::class) - ->addEntity('unit_test_models', '\App\Sharp\Entities\UnitTestModelEntity'); + sharp()->config() + ->declareEntity('\App\Sharp\Entities\UnitTestModelEntity'); // Now generate a reorder handler $this->artisan('sharp:generator') diff --git a/tests/Unit/Form/Fields/SharpFormUploadFieldTest.php b/tests/Unit/Form/Fields/SharpFormUploadFieldTest.php index 89fe4de3d..38864d892 100644 --- a/tests/Unit/Form/Fields/SharpFormUploadFieldTest.php +++ b/tests/Unit/Form/Fields/SharpFormUploadFieldTest.php @@ -10,7 +10,6 @@ ->toEqual([ 'key' => 'file', 'type' => 'upload', - 'imageCompactThumbnail' => false, 'imageTransformable' => true, 'imageTransformKeepOriginal' => true, 'maxFileSize' => sharp()->config()->get('uploads.max_file_size'), @@ -18,14 +17,6 @@ ]); }); -it('allows to define compactThumbnail', function () { - $formField = SharpFormUploadField::make('file') - ->setImageCompactThumbnail(); - - expect($formField->toArray()) - ->toHaveKey('imageCompactThumbnail', true); -}); - it('allows to define transformable', function () { $formField = SharpFormUploadField::make('file') ->setImageTransformable(false); diff --git a/tests/Unit/Form/Validator/SharpValidatorTest.php b/tests/Unit/Form/Validator/SharpValidatorTest.php deleted file mode 100644 index a426e5a44..000000000 --- a/tests/Unit/Form/Validator/SharpValidatorTest.php +++ /dev/null @@ -1,66 +0,0 @@ -validator->resolver(function ($translator, $data, $rules, $messages) { - return new SharpValidator($translator, $data, $rules, $messages); - }); -}); - -it('converts text suffixed data in the messages bag', function () { - $validator = $this->app->validator->make([ - 'name' => 'John Wayne', - ], [ - 'name' => 'required', - 'bio.text' => 'required', - ]); - - $validator->passes(); - - expect($validator->messages()->toArray()) - ->toEqual(['bio' => ['The bio field is required.']]); -}); - -it('does not convert non text suffixed data in the messages bag', function () { - $validator = $this->app->validator->make([ - ], [ - 'name' => 'required', - ]); - - $validator->passes(); - - expect($validator->messages()->toArray()) - ->toEqual(['name' => ['The name field is required.']]); -}); - -it('is compatible with laravel validation exception', function () { - $exception = ValidationException::withMessages([ - 'name' => ['Test'], - ]); - - expect($exception->errors()) - ->toEqual(['name' => ['Test']]); -}); - -it('handles localized text suffixed data in the messages bag', function () { - $validator = $this->app->validator->make([ - 'name' => 'Marie Curie', - 'bio' => [ - 'text' => [ - 'en' => '', - 'fr' => 'Une femme formidable', - ], - ], - ], [ - 'name' => 'required', - 'bio.text.en' => 'required', - ]); - - $validator->passes(); - - expect($validator->messages()->toArray()) - ->toEqual(['bio.en' => ['The bio.en field is required.']]); -}); diff --git a/tests/Unit/Show/SharpShowTestDefault.php b/tests/Unit/Show/SharpShowTestDefault.php index bfdaa9e4c..0a91996c4 100644 --- a/tests/Unit/Show/SharpShowTestDefault.php +++ b/tests/Unit/Show/SharpShowTestDefault.php @@ -150,20 +150,6 @@ public function buildShowLayout(ShowLayout $showLayout): void expect($sharpShow->showLayout()['sections'][0]['key'])->toEqual('my-section'); }); -it('allows to declare a multiformAttribute', function () { - $sharpShow = new class() extends FakeSharpShow - { - public function buildShowConfig(): void - { - $this->configureMultiformAttribute('role'); - } - }; - - $sharpShow->buildShowConfig(); - - expect($sharpShow->showConfig(1)) - ->toHaveKey('multiformAttribute', 'role'); -}); it('allows to set an edit button label', function () { $sharpShow = new class() extends FakeSharpShow diff --git a/tests/Unit/Utils/CurrentSharpRequestTest.php b/tests/Unit/Utils/CurrentSharpRequestTest.php deleted file mode 100644 index ad3439f0c..000000000 --- a/tests/Unit/Utils/CurrentSharpRequestTest.php +++ /dev/null @@ -1,75 +0,0 @@ -fakeBreadcrumbWithUrl('/sharp/root/s-list/person/s-show/person/1/s-form/child/2'); - - expect(currentSharpRequest()->isForm())->toBeTrue() - ->and(currentSharpRequest()->isUpdate())->toBeTrue() - ->and(currentSharpRequest()->isCreation())->toBeFalse() - ->and(currentSharpRequest()->isShow())->toBeFalse() - ->and(currentSharpRequest()->isEntityList())->toBeFalse(); -}); - -it('allows to get form creation state from request', function () { - // We have to define "child" as a non-single form - app()->bind('child_entity', fn () => new class() extends SharpEntity {}); - sharp()->config()->addEntity('child', 'child_entity'); - - $this->fakeBreadcrumbWithUrl('/sharp/root/s-list/person/s-show/person/1/s-form/child'); - - expect(currentSharpRequest()->isForm())->toBeTrue() - ->and(currentSharpRequest()->isUpdate())->toBeFalse() - ->and(currentSharpRequest()->isCreation())->toBeTrue() - ->and(currentSharpRequest()->isShow())->toBeFalse() - ->and(currentSharpRequest()->isEntityList())->toBeFalse(); -}); - -it('allows to get show state from request', function () { - $this->fakeBreadcrumbWithUrl('/sharp/root/s-list/person/s-show/person/1'); - - expect(currentSharpRequest()->isForm())->toBeFalse() - ->and(currentSharpRequest()->isUpdate())->toBeFalse() - ->and(currentSharpRequest()->isCreation())->toBeFalse() - ->and(currentSharpRequest()->isShow())->toBeTrue() - ->and(currentSharpRequest()->isEntityList())->toBeFalse(); -}); - -it('allows to get entity list state from request', function () { - $this->fakeBreadcrumbWithUrl('/sharp/root/s-list/person'); - - expect(currentSharpRequest()->isForm())->toBeFalse() - ->and(currentSharpRequest()->isUpdate())->toBeFalse() - ->and(currentSharpRequest()->isCreation())->toBeFalse() - ->and(currentSharpRequest()->isShow())->toBeFalse() - ->and(currentSharpRequest()->isEntityList())->toBeTrue(); -}); - -it('allows to get current breadcrumb item from request', function () { - $this->fakeBreadcrumbWithUrl('/sharp/root/s-list/person/s-show/person/1/s-form/child/2'); - - expect(currentSharpRequest()->getCurrentBreadcrumbItem()->isForm())->toBeTrue() - ->and(currentSharpRequest()->getCurrentBreadcrumbItem()->isSingleForm())->toBeFalse() - ->and(currentSharpRequest()->getCurrentBreadcrumbItem()->entityKey())->toBe('child') - ->and(currentSharpRequest()->getCurrentBreadcrumbItem()->instanceId())->toEqual(2); -}); - -it('allows to get previous show from request', function () { - $this->fakeBreadcrumbWithUrl('/sharp/root/s-list/person/s-show/person/42/s-form/child/2'); - - expect(currentSharpRequest()->getPreviousShowFromBreadcrumbItems()->entityKey())->toBe('person') - ->and(currentSharpRequest()->getPreviousShowFromBreadcrumbItems()->instanceId())->toEqual(42); -}); - -it('allows to get previous show of a given key from request', function () { - $this->fakeBreadcrumbWithUrl('/sharp/root/s-list/person/s-show/person/31/s-show/person/42/s-show/child/84/s-form/child/84'); - - expect(currentSharpRequest()->getPreviousShowFromBreadcrumbItems()->entityKey())->toBe('child') - ->and(currentSharpRequest()->getPreviousShowFromBreadcrumbItems()->instanceId())->toEqual(84) - ->and(currentSharpRequest()->getPreviousShowFromBreadcrumbItems('person')->entityKey())->toBe('person') - ->and(currentSharpRequest()->getPreviousShowFromBreadcrumbItems('person')->instanceId())->toEqual(42); -}); diff --git a/tests/Unit/Utils/SharpEntityManagerTest.php b/tests/Unit/Utils/SharpEntityManagerTest.php index e18f9081d..754a0102c 100644 --- a/tests/Unit/Utils/SharpEntityManagerTest.php +++ b/tests/Unit/Utils/SharpEntityManagerTest.php @@ -13,13 +13,6 @@ ->toBeInstanceOf(PersonEntity::class); }); -it('returns an entity declared in the deprecated way in configuration', function () { - sharp()->config()->addEntity('another-person', PersonEntity::class); - - expect(app(SharpEntityManager::class)->entityFor('another-person')) - ->toBeInstanceOf(PersonEntity::class); -}); - it('throws an exception on unknown entity', function () { app(SharpEntityManager::class)->entityFor('person'); })->throws(SharpInvalidEntityKeyException::class); diff --git a/tests/Unit/Utils/SharpMenuTest.php b/tests/Unit/Utils/SharpMenuTest.php index 45163a380..5a630f217 100644 --- a/tests/Unit/Utils/SharpMenuTest.php +++ b/tests/Unit/Utils/SharpMenuTest.php @@ -5,13 +5,13 @@ use Code16\Sharp\Utils\Menu\SharpMenu; it('allows to add an entity link with its key in the menu', function () { - sharp()->config()->addEntity('my-entity', PersonEntity::class); + sharp()->config()->declareEntity(PersonEntity::class); $menu = new class() extends SharpMenu { public function build(): SharpMenu { - return $this->addEntityLink('my-entity', 'test', 'fa-user'); + return $this->addEntityLink('person', 'test', 'fa-user'); } }; @@ -19,8 +19,8 @@ public function build(): SharpMenu ->getLabel()->toEqual('test') ->getIcon()->toEqual('fa-user') ->isEntity()->toBeTrue() - ->getEntityKey()->toEqual('my-entity') - ->getUrl()->toEqual(route('code16.sharp.list', 'my-entity')); + ->getEntityKey()->toEqual('person') + ->getUrl()->toEqual(route('code16.sharp.list', 'person')); }); it('allows to add an entity link with its entity class name in the menu', function () { @@ -102,7 +102,7 @@ public function build(): SharpMenu }); it('allows to group links in sections', function () { - sharp()->config()->addEntity('my-entity', PersonEntity::class); + sharp()->config()->declareEntity(PersonEntity::class); $menu = new class() extends SharpMenu { @@ -110,7 +110,7 @@ public function build(): SharpMenu { return $this->addSection( 'my section', - fn ($section) => $section->addEntityLink('my-entity', 'test', 'fa-user') + fn ($section) => $section->addEntityLink('person', 'test', 'fa-user') ); } }; diff --git a/tests/Unit/Utils/Testing/SharpLegacyAssertionsTest.php b/tests/Unit/Utils/Testing/SharpLegacyAssertionsTest.php index 6f4a5ae17..5eecfa119 100644 --- a/tests/Unit/Utils/Testing/SharpLegacyAssertionsTest.php +++ b/tests/Unit/Utils/Testing/SharpLegacyAssertionsTest.php @@ -169,35 +169,6 @@ ); }); -it('allows to test getSharpForm for edit with a custom breadcrumb with legacy API', function () { - $response = fakeResponse() - ->withSharpCurrentBreadcrumb( - ['list', 'leaves'], - ['show', 'leaves', 6], - ) - ->getSharpForm('leaves', 6); - - $this->assertEquals( - route('code16.sharp.form.edit', ['s-list/leaves/s-show/leaves/6', 'leaves', 6]), - $response->uri, - ); -}); - -it('allows to define a current breadcrumb with legacy API', function () { - $response = fakeResponse() - ->withSharpCurrentBreadcrumb( - ['list', 'trees'], - ['show', 'trees', 2], - ['show', 'leaves', 6], - ) - ->getSharpForm('leaves', 6); - - $this->assertEquals( - 'http://localhost/sharp/root/s-list/trees/s-show/trees/2/s-show/leaves/6/s-form/leaves/6', - $response->uri, - ); -}); - it('allows to test getSharpForm for edit with global filter keys', function () { fakeGlobalFilter('test-1');