Skip to content

Commit 500ddfb

Browse files
committed
Note Link field return type change in upgrade guide
1 parent 1cb3540 commit 500ddfb

File tree

1 file changed

+53
-1
lines changed

1 file changed

+53
-1
lines changed

docs/5.x/upgrade.md

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,54 @@ The reusability of entry types means that some GraphQL queries have changed.
334334
}
335335
```
336336
337+
### Field Types
338+
339+
#### URL &rarr; 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 function getUrl(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 function getUrl(Element $element, string $fieldHandle): LinkData
362+
{
363+
// The return type 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 function getUrl(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+
337385
## Elements & Content
338386
339387
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
349397
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:
350398
351399
::: code
352-
```twig{10} Twig
400+
```twig{12} Twig
353401
{# Locate the field layout element that would save to the desired column: #}
354402
{% set entryType = craft.app.entries.getEntryTypeByHandle('post') %}
355403
{% set fieldLayout = entryType.getFieldLayout() %}
356404
{% set sourceField = fieldLayout.getFieldByHandle('sourceMedia') %}
357405
406+
{# (Craft 5.2 introduced the `entryType('post')` shortcut function!) #}
407+
358408
{% set entriesFromPhysicalMedia = craft.entries()
359409
.section('news')
360410
.andWhere([
@@ -432,6 +482,8 @@ Queries for nested entries will be largely the same—equivalent methods have be
432482
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 type for that block would get the handle `gallery1` (or potentially `gallery2`, `gallery3`, and so on, if multiple similar Matrix fields are being migrated).
433483
434484
Visit **Settings** &rarr; **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._
435487
:::
436488
437489
### Eager-Loading

0 commit comments

Comments
 (0)