Skip to content

Commit 1c143da

Browse files
authored
Merge pull request #640 from craftcms/5.3
5.3
2 parents b5473a6 + 2e826c3 commit 1c143da

21 files changed

+378
-106
lines changed

_redirects

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
/docs/commerce/3.x/shipping-methods.html /docs/commerce/3.x/extend/shipping-methods.html
4747
/docs/commerce/3.x/update-cart-addresses.html /docs/commerce/3.x/addresses.html#updating-cart-addresses
4848
/docs/commerce/4.x/update-cart-custom-fields.html /docs/commerce/4.x/orders-carts.html#storing-data-in-custom-fields
49+
/docs/5.x/reference/field-types/url.html /docs/5.x/reference/field-types/link.html
4950

5051
/docs/nitro/2.x/services/ /docs/nitro/2.x/
5152
/docs/nitro/usage.html /docs/nitro/2.x/usage.html

docs/.vuepress/sets/craft-cms.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ module.exports = {
5454
"field-types/entries",
5555
"field-types/icon",
5656
"field-types/lightswitch",
57+
"field-types/link",
5758
"field-types/matrix",
5859
"field-types/money",
5960
"field-types/multi-select",
@@ -63,7 +64,6 @@ module.exports = {
6364
"field-types/table",
6465
"field-types/tags",
6566
"field-types/time",
66-
"field-types/url",
6767
"field-types/users",
6868
],
6969
},

docs/5.x/extend/updating-plugins.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -341,10 +341,6 @@ Craft handles multi-instance fields for you, at the field layout level.
341341

342342
You can explicitly opt out of multi-instance support by returning `false` from a static `isMultiInstance()` method. By default, Craft treats all field types as multi-instance unless its `dbType()` method returns `null`.
343343

344-
::: tip
345-
We will provide a console command for users to merge field definitions that are made redundant by multi-instance support.
346-
:::
347-
348344
#### Presentation
349345

350346
Field types whose content is useful in [element cards](#element-chips-cards) should implement `PreviewableFieldInterface`. In addition to determining whether the field can be displayed in element indexes, previewable fields are now eligible for inclusion in element cards when building field layouts.

docs/5.x/images/custom-source.png

-128 KB
Binary file not shown.
Loading
-124 KB
Binary file not shown.
284 KB
Loading

docs/5.x/images/fields-link-ui.png

99.4 KB
Loading

docs/5.x/images/fields-new.png

285 KB
Loading

docs/5.x/images/users-new.png

196 KB
Loading

docs/5.x/reference/element-types/addresses.md

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ Address queries support the following parameters:
9696

9797
## Address Repository
9898

99-
The [commerceguys/addressing](https://github.com/commerceguys/addressing) library powers planet-friendly address handling and formatting, and its exhaustive repository of global address information is available to all Craft projects. If you need a list of countries, states, or provinces, for example, you can fetch them via Craft’s [Addresses](craft5:craft\services\Addresses) service, from Twig templates or PHP:
99+
The [commerceguys/addressing](repo:commerceguys/addressing) library powers planet-friendly address handling and formatting, and its exhaustive repository of global address information is available to all Craft projects. If you need a list of countries, states, or provinces, for example, you can fetch them via Craft’s [Addresses](craft5:craft\services\Addresses) service, from Twig templates or PHP:
100100

101101
::: code
102102
```twig
@@ -107,7 +107,7 @@ $countries = Craft::$app->getAddresses()->getCountryRepository()->getAll();
107107
```
108108
:::
109109

110-
This returns an array of [Country](https://github.com/commerceguys/addressing/blob/master/src/Country/Country.php) objects, indexed by their two-letter code. You might use this to populate a drop-down menu:
110+
This returns an array of [Country](repo:commerceguys/addressing/blob/master/src/Country/Country.php) objects, indexed by their two-letter code. You might use this to populate a drop-down menu:
111111

112112
```twig
113113
<select name="myCountry">
@@ -256,7 +256,25 @@ The default formatter includes the following options:
256256

257257
#### Country Names
258258

259-
Only the two-letter “country code” is stored on addresses. To display the full country name (localized for the viewer), you must retrieve its definition from the [address repository](#address-repository):
259+
Only the two-letter “country code” is stored on addresses. To display the full country name (localized for the viewer), use the attached [`Country`](repo:commerceguys/addressing/blob/master/src/Country/Country.php) model: <Since ver="5.3.0" feature="Address.getCountry()" />
260+
261+
```twig
262+
{% set country = address.country %}
263+
264+
{{ country.name }}
265+
```
266+
267+
Via the `Country` object, you also have access to the following data:
268+
269+
- `countryCode` — Same ISO 3166-1 alpha-2 code as was stored on `address.countryCode`.
270+
- `name` — Name of the country, localized for the current site.
271+
- `threeLetterCode` — ISO 3166-1 alpha-3 code for the country.
272+
- `numericalCode` — ISO ISO 3166-1 numeric codes.
273+
- `currencyCode` — ISO 4217 currency code (not the symbol).
274+
- `timezones` — A list of PHP timezone identifiers for the country. This is not necessarily specific to the address!
275+
- `locale` — How the country’s name was localized.
276+
277+
In earlier versions of Craft, you must directly retrieve its definition from the [address repository](#address-repository):
260278

261279
```twig
262280
{% set country = craft.app.getAddresses().getCountryRepository().get(address.countryCode) %}

docs/5.x/reference/element-types/entries.md

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -132,23 +132,23 @@ Types of content that might benefit from being defined as a structure include…
132132

133133
Just like channels, entries in structures can be assigned [types](#entry-types). Structures offer great flexibility in presentation—in particular, the ability to collect nested content on a parent page, or alter the appearance of pages based on their hierarchical “depth” within a bundle of content.
134134

135-
::: tip
136-
Structures can also make use of the **Maintain Hierarchy** setting on entries fields.
137-
:::
135+
Structures have the following additional settings:
138136

139-
Entries belonging to a structure are discrete from [nested entries](#nested-entries) in [Matrix](../field-types/matrix.md) fields. Structure entries can be freely moved around in their hierarchy (receiving new “parent” elements in the process), whereas nested entries are always owned by the element they were created within.
137+
Max Levels
138+
: Decide how many levels deep authors can organize entries.
140139

141-
#### Custom Sources
140+
Default Entry Placement
141+
: Choose where new entries are placed in the structure. This setting applies when that entry has no parent entry (before or after other “root” entries), _and_ when a parent is selected (before or after other entries with the same parent), as well as when an entry is [moved](#moving-entries-between-sections) into the section. <Since ver="5.3.0" feature="Moving entries between sections" />
142142

143-
Special element sources based on existing Singles, Channels, and Structures by creating _custom sources_. Each custom source lists all entries by default, but can be filtered to only those that meet the specified **Entry Criteria**.
143+
Structures can also make use of the **Maintain Hierarchy** setting on [entries fields](../field-types/entries.md).
144144

145-
To create a new custom source, go to **Entries****Customize Sources** (under the three dots in the sources sidebar), and from the bottom-left “+” menu choose **New custom source**:
145+
::: tip
146+
Entries belonging to a structure are discrete from [nested entries](#nested-entries) in [Matrix](../field-types/matrix.md) fields. Structure entries can be freely moved around in their hierarchy (receiving new “parent” elements in the process), whereas nested entries are always owned by the element they were created within.
147+
:::
146148

147-
![Screenshot of a modal window with fields for a new custom source: Label, Condition Builder, and Table Columns](../../images/custom-source.png)
149+
#### Custom Sources
148150

149-
::: warning
150-
This same interface is available in the search bar of any [element index](../../system/elements.md#indexes), but the condition builder interface will differ in subtle ways, as custom sources are stored in Project Config.
151-
:::
151+
You can supplement the automatic [sources](../../system/elements.md#sources) presented in the entries [element index](../../system/elements.md#indexes) with _custom sources_. Each custom source lists all entries by default, but can be filtered to only those that meet the specified **Entry Criteria**.
152152

153153
### Entry URI Formats
154154

@@ -272,11 +272,23 @@ You can pass the token via either a query string parameter named after your <con
272272
For live preview, you should also consider [enabling iFrame Resizer](config5:useIframeResizer) so that Craft can maintain the page scroll position between page loads.
273273
:::
274274

275+
### Moving Entries Between Sections <Since ver="5.3.0" feature="Transferring entries between sections" />
276+
277+
Entries in [channel](#channels) and [structure](#structures) sections cane be moved to other sections that support the same [entry type](#entry-types). Use the **Move to…** element action from any entry element index, then select the new section. If the action is disabled, the entry has no suitable targets—you may be able to change its entry type _in-situ_, reconcile any custom field changes, then move it to a compatible section.
278+
279+
When moving an entry, it’s important to note these behaviors:
280+
281+
- If the new section is a structure, the entry will be placed at the root, according to its **Default Entry Placement** setting.
282+
- Drafts and revisions will be moved along with the entry and remain accessible, but only drafts that use an entry type that is allowed in the new section can be restored—same as if an entry type were _removed_ from a section.
283+
- If the new section has a lower **Max authors** setting, author data will remain intact and produce a validation error when saved.
284+
- Authors who don’t have access to the new section will also be removed, the next time the entry is saved. Permissions are still checked based on the section, not authorship.
285+
- Singles will never appear as targets for moving an entry.
286+
275287
## Nested Entries
276288

277289
Entries also power the [Matrix](../field-types/matrix.md) and [CKEditor](plugin:ckeditor) fields, which means your [entry types](#entry-types) can represent entire pages, or the building blocks thereof. How you implement your content model and authoring experience is entirely up to you!
278290

279-
Nested entries are an implementation of nested _elements_, a broader category of “owned” elements that also includes [addresses](addresses.md).
291+
Nested entries are an implementation of nested _elements_, a broader category of “owned” elements that includes [addresses](addresses.md) and powers Commerce’s product and variant architecture.
280292

281293
## Editing Entries
282294

docs/5.x/reference/element-types/users.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ related:
1212

1313
# Users
1414

15-
Users are Craft’s representation of people.
15+
A user is a special type of element that represents a person.
1616

1717
<!-- more -->
1818

@@ -90,7 +90,7 @@ By {{ collect(entry.authors).pluck('fullName').join(', ', ', and ') }}
9090

9191
### URLs
9292

93-
Unlike most other element types, users do _not_ have a “URI format” setting, and are not factored into routing.
93+
Unlike most other element types, users do _not_ have a “URI format” setting or support slugs, and are not factored into routing.
9494

9595
## Querying Users
9696

docs/5.x/reference/field-types/country.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@ Craft stores the field’s value as a capitalized, two-letter country code.
2626
{% endif %}
2727
```
2828

29-
To get more information about the country, use the [address repository](../element-types/addresses.md#address-repository) available via the address service:
29+
Craft actually returns a [`Country`](repo:commerceguys/addressing/blob/master/src/Country/Country.php) object, which has a few [additional features](../element-types/addresses.md#country-names), including the complete name (localized for the current site): <Since ver="5.3.0" description="{product} {ver} changed the data type for Country fields." />
30+
31+
```twig
32+
<h1>Mail from {{ entry.country.name }}</h1>
33+
```
34+
35+
In earlier versions of Craft, use the [address repository](../element-types/addresses.md#address-repository) available via the address service to get a `Country` model:
3036

3137
```twig
3238
{# Load all country data: #}
@@ -45,16 +51,19 @@ The `country` variable in this example is an instance of [`CommerceGuys\Address
4551

4652
You can query for elements based on a country field’s value in a familiar way:
4753

48-
```twig
49-
54+
```twig{3-4}
5055
{% set letters = craft.entries
5156
.section('letters')
5257
.fromCountry('FR')
5358
.toCountry('GB')
54-
.dateSent()
59+
.orderBy('dateSent DESC')
5560
.all() %}
5661
```
5762

63+
::: warning
64+
Queries against country fields currently only support two-letter codes, not complete names or other country properties.
65+
:::
66+
5867
### Front-end Forms
5968

6069
Update the value of a country field on an element by submitting a two-letter country code to the [`entries/save-entry` action](../controller-actions.md#post-entries-save-entry). Supposing we are in a template used by the “Letters” section from the previous example, our form might look something like this:

docs/5.x/reference/field-types/icon.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@ Icon fields allow the user to pick from a curated list of [FontAwesome](https://
44

55
<!-- more -->
66

7+
## Settings
8+
9+
To make FontAwesome Pro icons available, turn on the **Include Pro Icons** option. You may need to purchase a FontAwesome Pro license to use icons in your site’s front-end.
10+
711
## Development
812

9-
The saved value is suitable for use in the front-end with your own FontAwesome library, or Craft’s bundled subset.
13+
The saved value is suitable for use in the front-end with your own FontAwesome library.
1014

1115
### Webfonts
1216

@@ -18,6 +22,15 @@ Following the official [web fonts tutorial](https://fontawesome.com/docs/web/set
1822

1923
Change `fa-solid` to another style identifier to suit your site’s appearance!
2024

25+
If you added the FontAwesome files in `web/assets/fontawesome/*`, you would link to one or more style sheets like this:
26+
27+
```twig
28+
{% css '/assets/fontawesome/fontawesome.css' %}
29+
{% css '/assets/fontawesome/solid.css' %}
30+
```
31+
32+
You can add [`css` tags](../twig/tags.md#css) like this anywhere in your code and Craft will hoist them into the `<head>` of the document!
33+
2134
### SVG + JS
2235

2336
The same HTML will work with the recommendations in the [SVG + JS tutorial](https://fontawesome.com/docs/web/setup/host-yourself/svg-js).
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
---
2+
related:
3+
- uri: ../../system/fields.md
4+
label: Learn about content and custom fields
5+
---
6+
7+
# Link Fields <Badge text="New!" />
8+
9+
::: tip
10+
The link field replaced the URL field in [Craft 5.3](github:craftcms/cms/releases/5.3.0). Your existing fields will be automatically enhanced with the new UI. If you want to take advantage of the new features (like linking to assets, categories, and entries), check out the field’s edit screen.
11+
:::
12+
13+
Link fields provide a flexible way to link to on- and off-site resources, including assets, categories, entries, email addresses, phone numbers, or arbitrary URLs.
14+
15+
![Screenshot of the link field interface in the Craft control panel](../../images/fields-link-ui.png)
16+
17+
A link field’s value (when populated) is always suitable for use as an anchor tag’s `href` attribute:
18+
19+
```twig
20+
<a href="{{ supportType.action }}">{{ supportType.title }}</a>
21+
```
22+
23+
<!-- more -->
24+
25+
## Settings
26+
27+
<BrowserShot
28+
url="https://my-craft-project.ddev.site/admin/settings/fields/new"
29+
:link="false"
30+
:max-height="500"
31+
caption="Adding a new link field via the control panel.">
32+
<img src="../../images/fields-link-settings.png" alt="Link field settings screen in the Craft control panel">
33+
</BrowserShot>
34+
35+
In addition to the standard field options, Link fields have the following settings:
36+
37+
- **Allowed Link Types** — The type of resource(s) that can be linked. Selecting more than one link type displays a dropdown menu for the author.
38+
- **URL** — The value must be a valid URL, beginning with `http://` or `https://`.
39+
- **Asset** — Select an [asset](../element-types/assets.md) element.
40+
- **Category** — Select a [category](../element-types/categories.md) element.
41+
- **Email** — The value is automatically prepended with `mailto:`.
42+
- **Entry** — Select an [entry](../element-types/entries.md) element.
43+
- **Phone** — The value is automatically prepended with `tel:`.
44+
- **Max Length** – The maximum number of characters the field can contain. (Defaults to `255`.)
45+
46+
When selecting a link type that references elements, Craft will display a set of checkboxes that allow you to limit selection to specific [sources](../../system/elements.md#sources)—and in the case of assets, the allowable file kinds.
47+
48+
## The Field
49+
50+
Link fields have—at minimum—an input specific to the allowed type of link. If more than one link type is allowed, a dropdown menu will be shown before the field, allowing the author to switch between them and use a specialized input to define a value.
51+
52+
## Development
53+
54+
Outputting a link field in a template will return a normalized value suitable for use in an anchor tag’s `href` attribute:
55+
56+
```twig
57+
{% if entry.myLinkFieldHandle %}
58+
<h3>Link</h3>
59+
{{ tag('a', {
60+
text: 'Learn More',
61+
href: entry.myLinkFieldHandle
62+
}) }}
63+
{% endif %}
64+
```
65+
66+
### `LinkData`
67+
68+
The link field returns a <craft5:craft\fields\data\LinkData> object. When used as a string, its value is intelligently coerced to something URL-like—for element links, the element’s URL; for phone links, the number prefixed with `tel:`; and so on!
69+
70+
You can check what type of link the author selected, or access a selected element, directly:
71+
72+
```twig
73+
{% if entry.myLinkFieldHandle.type == 'entry' %}
74+
{{ entry.myLinkFieldHandle.element.render() }}
75+
{% else %}
76+
{{ entry.myLinkFieldHandle.link }}
77+
{% endif %}
78+
```
79+
80+
The valid `type` values are `asset`, `category`, `email`, `entry`, `phone`, and `url`.
81+
82+
Like elements, you can also render a complete anchor tag:
83+
84+
```twig
85+
{{ entry.myLinkFieldHandle.link }}
86+
```
87+
88+
Craft will figure out the best textual representation of the link—a selected element’s `title`, the URL (sans protocol), or the raw phone number, for example.
89+
90+
### Relations
91+
92+
When using an element in a link field, Craft makes the corresponding connections in its [relations](../../system/relations.md) system. This means that you can query for elements via link fields, just like other [relational fields](../../system/relations.md#custom-fields):
93+
94+
```twig
95+
{% set backlinks = craft.entries()
96+
.relatedTo({
97+
targetElement: post,
98+
field: 'myLinkField',
99+
})
100+
.all() %}
101+
102+
{# -> Returns other entries connected to the given `post` via a specific link field. #}
103+
```
104+
105+
::: warning
106+
It is not currently possible to [eager-load](../../development/eager-loading.md) link field relationships, as their element type is not known until the field data is loaded.
107+
:::

docs/5.x/reference/field-types/url.md

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)