Skip to content

Commit 08f4b01

Browse files
authored
Merge pull request #683 from craftcms/5.6
Craft 5.6
2 parents fcbda73 + 975eea3 commit 08f4b01

34 files changed

+460
-135
lines changed

docs/.vuepress/components/Indent.vue

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<template>
2+
<div class="indent" :style="`width: ${level * 1.5}em;`">↳</div>
3+
</template>
4+
5+
<script>
6+
export default {
7+
props: {
8+
level: {
9+
type: Number,
10+
default: 1,
11+
},
12+
}
13+
};
14+
</script>
15+
16+
<style scoped>
17+
.indent {
18+
display: inline-block;
19+
text-align: right;
20+
}
21+
</style>

docs/4.x/addresses.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ $countries = Craft::$app->getAddresses()->getCountryRepository()->getAll();
115115
```
116116
:::
117117

118-
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:
118+
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 dropdown menu:
119119

120120
```twig
121121
<select name="myCountry">

docs/4.x/dev/global-variables.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Variable | Description
4444
[loginUrl](#loginurl) | The URL to the front-end Login page.
4545
[logoutUrl](#logouturl) | The URL to the front-end Logout page.
4646
[now](#now) | The current date/time.
47+
[primarySite](#primarysite) <Since ver="4.14.0" feature="Global Twig variable for the primary site" /> | In multi-site projects, the “primary” site.
4748
[setPasswordUrl](#setpasswordurl) | The URL to the front-end [Reset Password](kb:front-end-user-accounts#reset-password-forms) page.
4849
[siteName](#sitename) | The name of the current site.
4950
[siteUrl](#siteurl) | The base URL of the current site.
@@ -218,6 +219,23 @@ A [DateTime](http://php.net/manual/en/class.datetime.php) object set to the curr
218219
Today is {{ now|date('M j, Y') }}.
219220
```
220221

222+
### `primarySite` <Since ver="4.14.0" feature="Global Twig variable for the primary site" />
223+
224+
The _primary_ site (as designated in <Journey path="Settings, Sites" />), as an instance of <craft4:craft\models\Site>.
225+
226+
```twig
227+
{# Output the primary site’s name: #}
228+
We are a proud member of {{ primarySite.name }}
229+
230+
{# Link to a page on the primary site: #}
231+
{{ tag('a', {
232+
href: siteUrl('about/governance', siteId = primarySite.id),
233+
text: 'Learn about our family of businesses',
234+
}) }}
235+
```
236+
237+
`primarySite` will be a reference to the same object as [`currentSite`](#currentsite), when `currentSite.primary` is `true`. You can also retrieve the primary site via `craft.app.sites.primarySite`.
238+
221239
### `setPasswordUrl`
222240

223241
The URL to [`setPasswordRequestPath`](config4:setPasswordRequestPath) if it’s set. (This wraps the path in [`siteUrl`](#siteurl).)
Loading
34.3 KB
Loading

docs/5.x/images/entry-type-edit.png

482 KB
Loading
237 KB
Loading
-70.2 KB
Binary file not shown.
Loading
118 KB
Loading

docs/5.x/images/field-slideout.png

-135 KB
Binary file not shown.
293 KB
Loading

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

175 KB
Loading
121 KB
Loading

docs/5.x/images/mail-settings.png

68 KB
Loading

docs/5.x/images/system-messages.png

5.31 KB
Loading

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ $countries = Craft::$app->getAddresses()->getCountryRepository()->getAll();
107107
```
108108
:::
109109

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:
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 dropdown menu:
111111

112112
```twig
113113
<select name="myCountry">

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

Lines changed: 63 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,18 @@ Craft uses _entry types_ to define atomic units of content, which are then expos
2424

2525
<Block label="Global Entry Types">
2626

27-
Entry types became a global resource in Craft 5. This means you can define a content type _once_, then use it in multiple sections, as a [nested](#nested-entries) block in a Matrix field, or some combination of the two. As a result, some settings have moved around!
27+
Entry types became a global resource in Craft 5. This means you can define a content type _once_, then use it in multiple sections, as a [nested](#nested-entries) block in a [Matrix](../field-types/matrix.md) field, or some combination of the two. As a result, some settings have moved around!
2828

2929
Most importantly, you’ll manage entry types in the **Settings** &rarr; **Entry Types** screen—or create them on-the-fly when working on a section or Matrix field.
3030

3131
</Block>
3232

3333
<BrowserShot
34-
url="https://my-craft-project.ddev.site/admin/settings/sections/1/entry-types/1"
34+
url="https://my-craft-project.ddev.site/admin/settings/entry-types/1"
3535
:link="false"
36+
:max-height="450"
3637
caption="Editing an entry type in the control panel.">
37-
<img src="../../images/sections-and-entries-entry-types.png" alt="Screenshot of entry type settings">
38+
<img src="../../images/entry-type-edit.png" alt="Screenshot of entry type settings">
3839
</BrowserShot>
3940

4041
Entry types have the following settings:
@@ -49,6 +50,58 @@ Entry types have the following settings:
4950
- **Show the Status field** — Manually set each entry’s status, or allow it to be dictated by its usage.
5051
- **Field Layout** — Add and arrange [custom fields](../../system/fields.md) to suit your content model.
5152

53+
### Aliases <Since ver="5.6.0" feature="Entry type aliases" />
54+
55+
When attaching an entry type to a [section](#sections) or [field](../field-types/matrix.md), you can configure a local override for its **Name** and **Handle**. This affects labels in the control panel, but does _not_ change how you reference them in queries.
56+
57+
As an example, an _Announcement_ entry type could be used in a _News_ section and a _Content_ Matrix or [CKEditor](plugin:ckeditor) field; in the _Content_ field context, the entry type is given a new **Name** (_Banner_) and handle (`banner`). Authors would then see _Banner_ when selecting **New entry** in the CKEditor toolbar, but developers would need to continue using the original, global handle to directly query those nested entries:
58+
59+
```twig{3}
60+
{% set embeddedAnnouncements = craft.entries()
61+
.field('pageContent')
62+
.type('announcement')
63+
.all() %}
64+
```
65+
66+
However, when _accessing_ the entry type via those nested entries (or an entry within a section), the aliases are applied automatically:
67+
68+
```twig{2,8}
69+
{% set announcements = craft.entries()
70+
.type('announcement')
71+
.all() %}
72+
73+
{% for announcement in announcements %}
74+
<article>
75+
<h2>{{ announcement.title }}</h2>
76+
<span class="type">{{ announcement.type.name }}</span>
77+
{{ announcement.body|md }}
78+
</article>
79+
{% endfor %}
80+
```
81+
82+
In this example, `announcement.type.name` might resolve to _Critical Release_ in one section, but _New Face_ in another—even though we queried for them using the original, global handle. To access the global <craft5:craft\models\EntryType>, use `entry.type.original`.
83+
84+
This can help improve the legibility of templates, wherein the generic `announcement` handle doesn’t describe how the entry type is actually used:
85+
86+
```twig{2,8-11}
87+
{% for contentBlock in entry.myMatrixField %}
88+
<div class="content-block content-block--type-{{ contentBlock.type.handle }}">
89+
{% switch contentBlock.type.handle %}
90+
{% case 'carousel'}
91+
{# ... #}
92+
{% case 'recommended'}
93+
{# ... #}
94+
{% case 'banner' %}
95+
{# Perhaps “Banner” made more sense than “Announcement” in this context, when designing! #}
96+
<h3>{{ contentBlock.title }}</h3>
97+
{{ contentBlock.message|md }}
98+
{% default %}
99+
{{ contentBlock.render() }}
100+
{% endswitch %}
101+
</div>
102+
{% endfor %}
103+
```
104+
52105
### Dynamic Entry Titles
53106

54107
The **Default Title Format** field accepts an [object template](../../system/object-templates.md) (just like the **Entry URI Format** and preview target **URL Format** we looked, above), and is evaluated whenever entries with this type are saved _without an explicitly-set title_. A title format may be rendered multiple times, depending on the selected **Title Translation Method**.
@@ -67,7 +120,7 @@ The available translation methods are covered in the [custom fields documentatio
67120

68121
## Sections
69122

70-
Sections organize and expose entry types for content authors. In each section you can define the following:
123+
Sections organize and expose [entry types](#entry-types) for content authors. In each section you can define the following:
71124

72125
- Whether entries in the section have URLs;
73126
- What the entries’ URLs should look like;
@@ -80,15 +133,15 @@ If your project has multiple [sites](../../system/sites.md), your section can de
80133
- Which sites entries in the section should target;
81134
- Which sites entries are created in, by default;
82135

83-
To create a new section, go to **Settings****Sections** and choose **New Section**.
136+
To create a new section, go to <Journey path="Settings, Sections" /> and choose **New Section**.
84137

85138
### Section Types
86139

87140
Craft has three different types of sections:
88141

89142
#### Singles
90143

91-
![Illustration of Entries layout with “Singles” selected, showing “About Us”, “Contact” and “Home” entries](../../images/entry-types-singles.png)
144+
![Illustration of Entries layout with “Singles” selected, showing “About Us”, “Contact” and “Home” entries](../../images/section-types-singles.png)
92145

93146
Singles are used for one-off pages or content objects that have unique requirements, such as…
94147

@@ -106,7 +159,7 @@ A single’s **Status** controls can be hidden with the **Show the Status field*
106159

107160
#### Channels
108161

109-
![Illustration of Entries layout with a “Press Releases” channel selected, showing three dated news entries](../../images/entry-types-channels.png)
162+
![Illustration of Entries layout with a “Press Releases” channel selected, showing three dated news entries](../../images/section-types-channels.png)
110163

111164
Channels are used for lists or streams of similar content, such as…
112165

@@ -121,11 +174,11 @@ Entries in channels are intended to be queried and displayed ordered by one or m
121174

122175
Structures are an extension of channels that support explicit, hierarchical organization.
123176

124-
![Illustration of Entries layout with a “Galleries” structure selected, showing nested building and gallery entries with drag-and-drop handles](../../images/entry-types-structures.png)
177+
![Illustration of Entries layout with a “Galleries” structure selected, showing nested building and gallery entries with drag-and-drop handles](../../images/section-types-structures.png)
125178

126179
Unlike other section types, structure sections expose a **Structure** view option on their [element indexes](../../system/elements.md#indexes):
127180

128-
![Illustration of an element index’s “View” options with “Structure” selected.](../../images/entry-types-structure-view-mode.png)
181+
![Illustration of an element index’s “View” options with “Structure” selected.](../../images/section-types-structure-view-mode.png)
129182

130183
Types of content that might benefit from being defined as a structure include…
131184

@@ -166,7 +219,7 @@ When Craft matches a request to an entry, its section’s designated **Template*
166219

167220
Consider these tips for creating special URIs:
168221

169-
- A URI that evaluates to `__home__` (and nothing more) will be available at your site’s base path;
222+
- A URI that evaluates to `__home__` (and nothing more) will be available at your site’s base path (this should only be used for [singles](#singles));
170223
- An empty URI means the entry does not get a route and will not have a public URL—unless you define one manually via `routes.php`;
171224
- Any Twig statement can be used to output values in a URI template—including ones that query for other elements, e.g. `{{ craft.entries().section('mySingle').one().slug }}/news` (see note below);
172225
- [Aliases](../../configure.md#aliases-and-environment-variables) can be evaluated with the [`alias()` function](../twig/functions.md#alias): `{{ alias('@basePressUri') }}/news`, `{{ alias('@mySectionUri') }}`.

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,18 @@ By {{ collect(entry.authors).pluck('fullName').join(', ', ', and ') }}
9292

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

95+
### Affiliated Site <Since ver="5.6.0" feature="Affiliated sites for user elements" />
96+
97+
[Multi-site](../../system/sites.md) projects capture the site a user [registers](../../system/user-management.md#affiliated-site) from (or is assigned to by an admin). Add the **Affiliated Site** [field layout element](#custom-fields) to manage this in the control panel.
98+
99+
A user’s affiliated site can be accessed in a template via `user.affiliatedSite`:
100+
101+
```twig
102+
{% if currentUser.affiliatedSite %}
103+
You registered via {{ currentUser.affiliatedSite.name }}.
104+
{% endif %}
105+
```
106+
95107
## Querying Users
96108

97109
You can fetch users in your templates or PHP code using **user queries**.
Lines changed: 66 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,102 @@
11
# Color Fields
22

3-
Color fields give you a hexadecimal color input with a preview of the current color, and on browsers that support `<input type="color">`, clicking on the preview will open the browser’s color picker.
3+
Color fields provide a flexible way to store hexadecimal color values. You can define a [palette](#palette) to guide authors <Since ver="5.6.0" feature="Color field palettes" />, or use an [open-ended input](#custom-colors).
44

55
<!-- more -->
66

7+
![Screenshot of a color field interface in the Craft control panel](../../images/fields-color-ui.png)
8+
9+
## Settings
10+
11+
<BrowserShot
12+
url="https://my-craft-project.ddev.site/admin/settings/fields/new"
13+
:link="false"
14+
:max-height="500"
15+
caption="Adding a new color field via the control panel.">
16+
<img src="../../images/fields-color-settings.png" alt="Color field settings screen in the Craft control panel">
17+
</BrowserShot>
18+
19+
### Palette
20+
21+
Each field contains a **Palette** of colors that authors can select from a dropdown menu.
22+
23+
### Custom Colors
24+
25+
Turn on **Allow custom colors** to display a compact input and color preview UI. When used in conjunction with a palette, an additional **Custom…** option is listed at the bottom of the dropdown menu.
26+
27+
::: tip
28+
In [browsers that support `<input type="color">`](https://caniuse.com/input-color), clicking on the color preview “well” opens a native OS color picker.
29+
:::
30+
731
## Development
832

9-
Calling a Color field in your templates will return a <craft5:craft\fields\data\ColorData> object, or `null` if no color was selected.
33+
Accessing a color field returns a <craft5:craft\fields\data\ColorData> object, or `null` if no color was selected.
1034

11-
By default, the bare field handle will return a hexadecimal representation of that color:
35+
Casting a `ColorData` object to a string by outputting it directly produces a hexadecimal representation of the color:
1236

1337
::: code
1438
```twig
15-
{% if entry.myFieldHandle %}
39+
{% if entry.myColorField %}
1640
<style type="text/css">
1741
.content a {
18-
color: {{ entry.myFieldHandle }};
42+
{# Directly outputting the value... #}
43+
color: {{ entry.myColorField }};
1944
}
2045
.content b {
21-
{# same thing #}
22-
color: {{ entry.myFieldHandle.getHex() }};
46+
{# ...is equivalent to: #}
47+
color: {{ entry.myColorField.getHex() }};
2348
}
2449
</style>
2550
{% endif %}
2651
```
2752
```php
28-
if ($entry->myFieldHandle) {
29-
echo $entry->myFieldHandle;
30-
// same thing
31-
echo $entry->myFieldHandle->getHex();
53+
if ($entry->myColorField) {
54+
echo $entry->myColorField;
55+
// …is equivalent to…
56+
echo $entry->myColorField->getHex();
3257
}
3358
```
3459
:::
3560

36-
Here’s an impractical example illustrating each <craft5:craft\fields\data\ColorData> method:
61+
`ColorData` objects have a number of methods that streamline working with color values:
3762

3863
::: code
3964
```twig
40-
{% if entry.myFieldHandle %}
41-
{{ entry.myFieldHandle }} {# output: #e5422b #}
42-
{{ entry.myFieldHandle.getHex() }} {# output: #e5422b #}
43-
{{ entry.myFieldHandle.getRgb() }} {# output: rgb(229,66,43) #}
44-
{{ entry.myFieldHandle.getHsl() }} {# output: hsl(7,81%,90%) #}
45-
{{ entry.myFieldHandle.getLuma() }} {# output: 0.38820862745098 #}
46-
{{ entry.myFieldHandle.getHue() }} {# output: 7 #}
47-
{{ entry.myFieldHandle.getLightness() }} {# output: 90 #}
48-
{{ entry.myFieldHandle.getSaturation() }} {# output: 81 #}
49-
{{ entry.myFieldHandle.getRed() }} {# output: 229 #}
50-
{{ entry.myFieldHandle.getGreen() }} {# output: 66 #}
51-
{{ entry.myFieldHandle.getBlue() }} {# output: 43 #}
65+
{% if entry.myColorField %}
66+
{{ entry.myColorField }} {# output: #e5422b #}
67+
{{ entry.myColorField.getHex() }} {# output: #e5422b #}
68+
{{ entry.myColorField.getRgb() }} {# output: rgb(229,66,43) #}
69+
{{ entry.myColorField.getHsl() }} {# output: hsl(7,81%,90%) #}
70+
{{ entry.myColorField.getLuma() }} {# output: 0.38820862745098 #}
71+
{{ entry.myColorField.getHue() }} {# output: 7 #}
72+
{{ entry.myColorField.getLightness() }} {# output: 90 #}
73+
{{ entry.myColorField.getSaturation() }} {# output: 81 #}
74+
{{ entry.myColorField.getRed() }} {# output: 229 #}
75+
{{ entry.myColorField.getGreen() }} {# output: 66 #}
76+
{{ entry.myColorField.getBlue() }} {# output: 43 #}
5277
{% endif %}
5378
```
5479
```php
55-
if ($entry->myFieldHandle) {
56-
echo $entry->myFieldHandle; // output: #e5422b
57-
echo $entry->myFieldHandle->getHex(); // output: #e5422b
58-
echo $entry->myFieldHandle->getRgb(); // output: rgb(229,66,43)
59-
echo $entry->myFieldHandle->getHsl(); // output: hsl(7,81%,90%)
60-
echo $entry->myFieldHandle->getLuma(); // output: 0.38820862745098
61-
echo $entry->myFieldHandle->getHue(); // output: 7
62-
echo $entry->myFieldHandle->getLightness(); // output: 90
63-
echo $entry->myFieldHandle->getSaturation(); // output: 81
64-
echo $entry->myFieldHandle->getRed(); // output: 229
65-
echo $entry->myFieldHandle->getGreen(); // output: 66
66-
echo $entry->myFieldHandle->getBlue(); // output: 43
80+
if ($entry->myColorField) {
81+
echo $entry->myColorField; // output: #e5422b
82+
echo $entry->myColorField->getHex(); // output: #e5422b
83+
echo $entry->myColorField->getRgb(); // output: rgb(229,66,43)
84+
echo $entry->myColorField->getHsl(); // output: hsl(7,81%,90%)
85+
echo $entry->myColorField->getLuma(); // output: 0.38820862745098
86+
echo $entry->myColorField->getHue(); // output: 7
87+
echo $entry->myColorField->getLightness(); // output: 90
88+
echo $entry->myColorField->getSaturation(); // output: 81
89+
echo $entry->myColorField->getRed(); // output: 229
90+
echo $entry->myColorField->getGreen(); // output: 66
91+
echo $entry->myColorField->getBlue(); // output: 43
6792
}
6893
```
6994
:::
7095

7196
::: tip
72-
The example omits the `getL()`, `getS()`, `getR()`, `getG()`, and `getB()` methods, which are abbreviated forms of `getLuma()`, `getSaturation()`, `getRed()`, `getGreen()`, and `getBlue()` respectively.
97+
Refer to the [`ColorData`](craft5:craft\fields\data\ColorData) class reference for a complete list of methods!
7398
:::
99+
100+
## Querying by Color
101+
102+
There are no special query features for color fields; refer to the [plain text](plain-text.md) field for a list of standard string comparison syntaxes.

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ Email fields give you a normal text input that requires a valid email address.
1010

1111
<!-- more -->
1212

13+
::: tip
14+
The new [Link field](link.md) also supports email addresses.
15+
:::
16+
1317
## Settings
1418

1519
Email fields have the following settings:

0 commit comments

Comments
 (0)