Upgrading from 7.x to 8.x
Get new assets, clear cache
This is true for every update: be sure to grab the latest assets and to clear the view cache:
php artisan vendor:publish --provider="Code16\Sharp\SharpServiceProvider" --tag=assets
php artisan view:clear
Information
Due to the migration to Vite, all .js
, .css
files moved from/public/vendor/sharp
to /public/vendor/sharp/assets
.
implement Show::delete($id)
, remove Form::delete($id)
In Sharp 8 we decided to finally move the instance deletion (meaning the Delete command) where it belongs: in the Show Page and the Entity List, and not in the Form as it was before for legacy reasons. This implies that a new Delete command is added in each instance of the Entity List and in the Show Page (of course, depending on authorizations).
This means that the Form delete($id)
method is deprecated in v8 (and will be removed in 9.x), which may impact your code in two ways, depending on your situation:
- All Show Pages must now define a
delete($id)
method — it should be in most cases a copy / paste of the Formdelete($id)
. In this case, you should remove entirely the Formdelete($id)
method. - For entities without Show Pages, you are not required to update your code because Sharp will detect and call the
Form::delete()
method as a workaround; the right way though (required in 9.x) would be to move thedelete()
method to your Entity List implementation.
For custom delete confirmations, you should call the new SharpShow::configureDeleteConfirmationText(string $confirmationText)
and SharpEntityList::configureDelete(?bool $hide = false, ?string $confirmationText = null)
.
Note: the (undocumented) deleteSharpShow()
test assertion was also removed, use deleteSharpEntityList()
or deleteSharpShow()
instead.
All deprecated methods were removed
Methods that were deprecated in 7.x were removed entirely. This includes:
- handling sharp's menu and entity in
sharp.php
config file (use SharpMenu and SharpEntity classes instead) - policies which does not extend
Code16\Sharp\Auth\SharpEntityPolicy
(see Entity policies) - passing a closure for the
$collapsible
param ofShowLayout::addEntityListSection
(pass a boolean) - old test assertions for commands
SharpFormUploadField::setCroppable()
replaced withSharpFormUploadField::setTransformable()
(see Upload documentation)
Laravel 10+ and php 8.2+ required
It's not a breaking change but minimal requirements are now these.
New way to build Entity List layout
SharpEntityList
's buildListFields()
, buildListLayout()
and buildListLayoutForSmallScreens()
are now deprecated, in favor of an easier way to build the layout in a new buildList()
method.
This means we can replace this code from 7.x:
class PostList extends SharpEntityList
{
protected function buildListFields(EntityListFieldsContainer $fieldsContainer): void
{
$fieldsContainer
->addField(
EntityListField::make('cover'),
)
->addField(
EntityListField::make('title')
->setLabel('Title'),
)
->addField(
EntityListField::make('author:name')
->setLabel('Author')
->setSortable(),
)
->addField(
EntityListField::make('published_at')
->setLabel('Published at')
->setSortable(),
);
}
protected function buildListLayout(EntityListFieldsLayout $fieldsLayout): void
{
$fieldsLayout
->addColumn('cover', 1)
->addColumn('title', 4)
->addColumn('author:name', 3)
->addColumn('published_at', 4);
}
protected function buildListLayoutForSmallScreens(EntityListFieldsLayout $fieldsLayout): void
{
$fieldsLayout
->addColumn('title', 6)
->addColumn('published_at', 6);
}
// ...
}
With this in 8.x:
class PostList extends SharpEntityList
{
protected function buildList(EntityListFieldsContainer $fields): void
{
$fields
->addField(
EntityListField::make('cover')
->setWidth(1)
->hideOnSmallScreens(),
)
->addField(
EntityListField::make('title')
->setLabel('Title')
->setWidth(4)
->setWidthOnSmallScreens(6),
)
->addField(
EntityListField::make('author:name')
->setLabel('Author')
->setWidth(3)
->hideOnSmallScreens()
->setSortable(),
)
->addField(
EntityListField::make('published_at')
->setLabel('Published at')
->setWidth(4)
->setWidthOnSmallScreens(6)
->setSortable(),
);
}
// ...
}
The old API is still supported to avoid breaking changes, but is deprecated and will be removed in 9.x. This new format is the only one documented in 8.x, here: Building EntityList.
Middleware declaration in config file
Sharp now uses the middleware
key in the sharp.php
config file to declare the middleware to be applied to all routes. In the unlikely case that you were injecting / replacing a middleware, you should now update this config key.