You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/5.x/upgrade.md
+53-1Lines changed: 53 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -334,6 +334,54 @@ The reusability of entry types means that some GraphQL queries have changed.
334
334
}
335
335
```
336
336
337
+
### Field Types
338
+
339
+
#### URL → Link <Since ver="5.3.0" feature="Link fields" />
340
+
341
+
URL fields will be converted to [Link](reference/field-types/link.md) fields during the upgrade. Your templates _do not_ require any updates, but projects that use custom field values in PHP may need to update type hints or use a specific member of the new <craft5:craft\fields\data\LinkData> object:
342
+
343
+
::: code
344
+
```php Old
345
+
use craft\base\Element;
346
+
347
+
class MyHelper
348
+
{
349
+
public static functiongetUrl(Element$element, string $fieldHandle): string
350
+
{
351
+
return$element->$fieldHandle;
352
+
}
353
+
}
354
+
```
355
+
```php{6} New (Types)
356
+
use craft\base\Element;
357
+
use craft\fields\data\LinkData;
358
+
359
+
class MyHelper
360
+
{
361
+
public static functiongetUrl(Element$element, string $fieldHandle): LinkData
362
+
{
363
+
// The returntype is now an object instead of a string!
364
+
return$element->$fieldHandle;
365
+
}
366
+
}
367
+
```
368
+
```php{9} New (Member)
369
+
use craft\base\Element;
370
+
use craft\fields\data\LinkData;
371
+
372
+
class MyHelper
373
+
{
374
+
public static functiongetUrl(Element$element, string $fieldHandle): string
375
+
{
376
+
// The signature can stay the same if you return a specific property:
377
+
return$element->$fieldHandle->url;
378
+
}
379
+
}
380
+
```
381
+
:::
382
+
383
+
The new field type supports linking to elements, in addition to text-based URLs—[check out its options](reference/field-types/link.md#settings) to see if it can help simplify some of your authoring interfaces!
384
+
337
385
## Elements & Content
338
386
339
387
Craft 5 has an entirely new content storage architecture that underpins many other features.
@@ -349,12 +397,14 @@ Content is stored as a JSON blob, and is dynamically indexed by the database in
349
397
When using custom fields in [advanced `where()` conditions](development/element-queries.md#advanced-element-queries), you no longer need to manually assemble a database column prefix/suffix. Instead, Craft can generate the appropriate expression to locate values in the JSON content column:
350
398
351
399
::: code
352
-
```twig{10} Twig
400
+
```twig{12} Twig
353
401
{# Locate the field layout element that would save to the desired column: #}
354
402
{% set entryType = craft.app.entries.getEntryTypeByHandle('post') %}
355
403
{% set fieldLayout =entryType.getFieldLayout() %}
356
404
{% set sourceField = fieldLayout.getFieldByHandle('sourceMedia') %}
357
405
406
+
{# (Craft 5.2 introduced the `entryType('post')` shortcut function!) #}
407
+
358
408
{% set entriesFromPhysicalMedia =craft.entries()
359
409
.section('news')
360
410
.andWhere([
@@ -432,6 +482,8 @@ Queries for nested entries will be largely the same—equivalent methods have be
432
482
Values passed to the `type()` method of [entry queries](./reference/element-types/entries.md#querying-entries) may require updates, as migrated entry types _can_ receive new handles. For example, a Matrix field that contained a block type with the handle `gallery` might conflict with a preexisting entry type belonging to a section;in that event, the new entry typefor that block would get the handle `gallery1` (or potentially `gallery2`, `gallery3`, and so on, if multiple similar Matrix fields are being migrated).
433
483
434
484
Visit **Settings**→**Entry Types** to check if any handles appear to have collided in this way, then review and update templates as necessary.
485
+
486
+
_Matrix block IDs were not stable in Craft 4, and will change as they are converted to entry types. If you maintain code that loads Matrix block definitions by hard-coded IDs, it will no longer work in Craft 5._
0 commit comments