Skip to content

Commit

Permalink
more upgrade guiding
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonvarga committed Apr 9, 2024
1 parent 4615188 commit b95a760
Show file tree
Hide file tree
Showing 2 changed files with 150 additions and 1 deletion.
149 changes: 149 additions & 0 deletions content/collections/docs/4-to-5.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,42 @@ public function boot(): void
}
```

### Tag parameters that output HTML attributes are opt-in
**Affects apps using the `svg` tag or tags that output forms (such as `form:create`, `user:login_form`, `user:forgot_password_form`, etc.)**

In Statamic 4, if you added tag parameters that weren't recognized by the tag, it would output them as HTML attributes.

For example:

```antlers
{{ svg src="foo.svg" class="w-4 h-4" }}
Outputs: <svg class="w-4 h-4">...</svg>
```

In Statamic 5, you must explicitly add an `attr:` prefix in order for it to be output.

```antlers
{{ svg src="foo.svg" class="w-4 h-4" }}
Outputs: <svg>...</svg>
{{ svg src="foo.svg" attr:class="w-4 h-4" }}
Outputs: <svg class="w-4 h-4">...</svg>
```


## Low impact changes

### Regex Antlers Parser has been removed
**Affects apps that are still using the `regex` parser.**

The new Antlers parser was introduced in 3.3 and was made the default in 3.4.

You would have been using the old Parser if either of these apply:
- In `config/statamic/antlers.php`, the `version` was set to `regex`.
- The `antlers.php` file doesn't exist at all.

The newer parser should be backwards compatible but if you encounter any errors, you may need to check the [docs](/antlers).

### Validation rule changes
**Affects apps using `unique_entry_value`, `unique_term_value`, or `unique_user_value` rules.**

Expand All @@ -168,6 +202,13 @@ validate:
- 'new \Statamic\Rules\UniqueUserValue({id})' #[tl!++]
```

### Antlers sanitization
**Affects apps or addons using the `sanitize` modifier or the `Html::sanitize` method.**

The `sanitize` modifier (and `Html::sanitize()` method) method has changed under the hood from using `htmlentities` to `htmlspecialchars`.

This change allows for things like accent characters (ü, í, etc) to remain unescaped. This is likely what you want to happen anyway, but if you have a reason for them to be converted, you should use `entities` modifier or `Html::entities()` method respectively.

### Seed removed from `shuffle` modifier
**Affects apps using the shuffle modifier with an argument.**

Expand All @@ -180,6 +221,34 @@ In Laravel 11, the underlying randomization technique was made more secure and n
The shuffle modifier without an argument will continue to work without any modification needed.
### The `modify_date` modifier is now immutable
**Affects apps using the modify_date modifier.**
In Statamic 4, the `modify_date` modifier would modify date variable which would then be reflected elsewhere in your template.
In Statamic 5, this is fixed, but if you were relying on this incorrect behavior you will need to handle it.
```antlers
{{ date }} // 1st of may
{{ date | modify_date('+1 day') }} // 2nd of may
{{ date }} // 2nd of may {{# [tl! --] #}}
{{ date }} // 1st of may {{# [tl! ++] #}}
```

### The `svg` tag sanitizes by default
**Affects apps that use the `svg` tag.**

The `{{ svg }}` will now sanitize the output by default. This meant things like JavaScript or other valid but potentially insecure elements will be filtered out.

For most people this won't be a problem but if you rely on this advanced SVG features, you may want to disable it.

```antlers
{{ svg
src="foo.svg"
sanitize="false" {{# [tl! ++] #}}
}}
```

### Bard JS value is now an object
**Affects apps or addons that are manually targeting Bard's value in JS**

Expand All @@ -189,3 +258,83 @@ Previously, to prevent issues with how Laravel would trim whitespace on submitte
let bardValue = JSON.parse(getBardValue()); // [tl! --]
let bardValue = getBardValue(); // [tl! ++]
```

### Misc class method changes
The following methods have been removed:
- `Statamic\Entries\Collection::revisions()` removed. Use `revisionsEnabled()`.

The following interfaces have added `findOrFail()` methods:
- `Statamic\Contracts\Assets\AssetContainerRepository`
- `Statamic\Contracts\Assets\AssetRepository`
- `Statamic\Contracts\Auth\UserRepository`
- `Statamic\Contracts\Entries\CollectionRepository`
- `Statamic\Contracts\Entries\EntryRepository`
- `Statamic\Contracts\Globals\GlobalVariablesRepository`
- `Statamic\Contracts\Structures\NavigationRepository`
- `Statamic\Contracts\Taxonomies\TermRepository`

The following methods have changed:
- `Statamic\StaticCaching\Cacher::getCachedPage()` now returns a `Statamic\StaticCaching\Page`.

## Zero impact changes

These are items that you can completely ignore. They are suggestions on how to improve your code using newly added features.

### JS Slug generation

The `$slugify` JS API has been deprecated. This could be a good time to use the new slug helpers.

If you are generating simple slug/handles, you can use the global helper:

```js
let slug = this.$slugify('Foo Bar'); // foo-bar [tl! --]
let slug = str_slug('Foo Bar'); // foo-bar [tl! ++]

let handle = this.$slugify('Foo Bar', '_'); // foo_bar [tl! --]
let handle = snake_case('Foo Bar'); // foo_bar [tl! ++]
```

If your slugs need to factor in language logic (like an entry's slug would), then you can use the new server side feature:

```js
let slug = getSlug('Foo Bar'); // [tl! --:start]

function getSlug(value) {
return this.$slugify(value);
} // [tl! --:end]

let slug = await getSlug('Foo Bar'); // [tl! ++:start]

async function getSlug(value) {
return this.$slug.create('Foo Bar');
} // [tl! ++:end]
```


### Addon test case

If you have an addon, there's a good chance your `TestCase` is a bit complicated.

You should be able to extend the new `AddonTestCase` and specify your service provider in favor of manually wiring up all the Testbench bits.

```php
use Orchestra\Testbench\TestCase as OrchestraTestCase; // [tl! --]
use Statamic\Extend\AddonTestCase; // [tl! ++]

abstract class TestCase extends OrchestraTestCase // [tl! --]
abstract class TestCase extends AddonTestCase // [tl! ++]
{
protected string $addonServiceProvider = YourServiceProvider::class; // [tl! ++]

protected function getPackageProviders($app) // [tl! --:start]
{
return [
GraphQLServiceProvider::class,
StatamicServiceProvider::class,
YourServiceProvider::class,
];
}

// etc... [tl! --:end]
}
```
2 changes: 1 addition & 1 deletion content/collections/modifiers/modify_date.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ April 1, 2000
```

:::tip
This modifier **modifies the variable directly** which will be passed onto any additional modifiers.
As of Statamic 5, this modifier will return a copy of the Date. Earlier versions would **modify the variable directly** which will be passed onto any additional modifiers.
:::

0 comments on commit b95a760

Please sign in to comment.