Skip to content

Commit e7dc970

Browse files
authored
Merge pull request #699 from craftcms/releases/craft-5.7
Craft 5.7
2 parents 3df6066 + a10a35e commit e7dc970

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+871
-160
lines changed

docs/.vuepress/components/Block.vue

+11-16
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,19 @@
1+
<template>
2+
<div class="custom-block">
3+
<div v-if="label" class="banner">
4+
<span class="label">{{ label }}</span>
5+
</div>
6+
<div class="content">
7+
<slot />
8+
</div>
9+
</div>
10+
</template>
11+
112
<script>
213
export default {
3-
functional: true,
414
props: {
515
label: String,
616
},
7-
render(h, { props, slots }) {
8-
const content = [h('div', { class: 'content' }, slots().default)];
9-
10-
if (props.label) {
11-
content.unshift(h(
12-
'div',
13-
{
14-
class: 'banner',
15-
},
16-
[h('span', { class: 'label' }, props.label)]
17-
));
18-
}
19-
20-
return h('div', { class: 'custom-block' }, content);
21-
},
2217
};
2318
</script>
2419

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<template>
2+
<span class="placeholder" :title="help"><slot /></span>
3+
</template>
4+
5+
<script>
6+
export default {
7+
props: {
8+
help: {
9+
type: String,
10+
required: false,
11+
},
12+
},
13+
};
14+
</script>
15+
16+
17+
<style lang="postcss" scoped>
18+
.placeholder {
19+
@apply border border-dashed px-1;
20+
21+
font-size: 0.95em;
22+
cursor: help;
23+
}
24+
</style>
+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<template>
2+
<div :class="['status-label', getSlug()]">
3+
<div class="status-label-pip" :style="{ backgroundColor: getColor() }"></div>
4+
<div class="status-label-text">
5+
{{ label }}
6+
</div>
7+
</div>
8+
</template>
9+
10+
<script>
11+
export default {
12+
props: {
13+
label: {
14+
type: String,
15+
default: 'live',
16+
},
17+
color: {
18+
type: String,
19+
default: null,
20+
},
21+
},
22+
methods: {
23+
getSlug() {
24+
return this.label.toLowerCase().replace(/[^a-z]/, '-');
25+
},
26+
getColor() {
27+
if (!this.color) {
28+
return null;
29+
}
30+
31+
if (this.color.indexOf('#') !== 0) {
32+
return null;
33+
}
34+
35+
return this.color;
36+
},
37+
},
38+
};
39+
</script>
40+
41+
<style lang="postcss" scoped>
42+
.status-label {
43+
align-items: center;
44+
border-radius: 1em;
45+
display: inline-flex;
46+
height: 20px;
47+
padding: 0 10px 0 5px;
48+
49+
&.live {
50+
background-color: theme('colors.craft.green');
51+
}
52+
53+
&.pending {
54+
background-color: theme('colors.craft.orange');
55+
}
56+
}
57+
58+
.status-label-pip {
59+
background-color: white;
60+
border-radius: 100%;
61+
height: 12px;
62+
margin-right: 5px;
63+
width: 12px;
64+
}
65+
66+
.status-label-text {
67+
color: white;
68+
font-size: 0.7em;
69+
font-weight: 600;
70+
letter-spacing: 0.05em;
71+
text-transform: uppercase;
72+
}
73+
</style>

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

+2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ module.exports = {
4444
children: [
4545
"field-types/addresses",
4646
"field-types/assets",
47+
"field-types/button-group",
4748
"field-types/categories",
4849
"field-types/checkboxes",
4950
"field-types/color",
@@ -52,6 +53,7 @@ module.exports = {
5253
"field-types/dropdown",
5354
"field-types/email",
5455
"field-types/entries",
56+
"field-types/json",
5557
"field-types/icon",
5658
"field-types/lightswitch",
5759
"field-types/link",

docs/5.x/extend/element-types.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: Add native-feeling content types to empower content authors and adm
44

55
# Element Types
66

7-
[Elements](../system/elements.md) underpin Craft’s flexible and extensible content modeling features. You can supplement Craft’s eight [built-in element types](../system/elements.md#element-types) with your own, from a plugin or module.
7+
[Elements](../system/elements.md) underpin Craft’s flexible and extensible content modeling features. You can supplement Craft’s seven [built-in element types](../system/elements.md#element-types) with your own, from a plugin or module.
88

99
As you implement common element features like [titles](#titles), [sources](#sources), or [statuses](#statuses), the built-in element classes will be an invaluable resource—both as templates for basic functionality and evidence of the flexibility of elements.
1010

docs/5.x/extend/field-types.md

-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ class Plugin extends \craft\base\Plugin
5252

5353
If you used the generator to scaffold the field type, it ought to have inserted this, automatically. You may register as many field types as you wish, from one `EVENT_REGISTER_FIELD_TYPES` event handler.
5454

55-
###
56-
5755
### Missing Fields
5856

5957
If your field class ever goes missing (say, because a developer uninstalls your plugin or removes the package), Craft will use an instance of <craft5:craft\fields\MissingField>, and display a message in any field layouts it was present in. This ensures the control panel doesn’t become inoperable, but doesn’t prevent front-end templates from breaking.

docs/5.x/images/elements-statuses.png

51.4 KB
Loading
98.8 KB
Loading
70.7 KB
Loading
46.4 KB
Loading
Loading
82.6 KB
Loading
45.7 KB
Loading
257 KB
Loading
112 KB
Loading
523 KB
Loading

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

474 KB
Loading
164 KB
Loading

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

130 KB
Loading
Loading
90.6 KB
Loading
Loading
75.2 KB
Loading
295 KB
Loading

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

186 KB
Loading

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

+6
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ For compatibility and localization, core address components (aside from the Coun
4242

4343
You may set a default country for new addresses via the <config5:defaultCountryCode> setting.
4444

45+
### Copying Addresses <Since ver="5.7.0" feature="Copying addresses" />
46+
47+
Addresses can be copied and pasted between users and [addresses fields](../field-types/addresses.md).
48+
49+
<See path="../../system/elements.md" hash="copying-elements" label="Copying Elements" description="Learn how to copy addresses and other elements between contexts." />
50+
4551
## Querying Addresses
4652

4753
You can fetch addresses in your templates or PHP code using an [AddressQuery](craft5:craft\elements\db\AddressQuery).

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

+78-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ related:
66
label: Introduction to Elements
77
- uri: ../field-types/entries.md
88
label: Entries Fields
9+
sidebarDepth: 2
910
---
1011

1112
# Entries
@@ -126,8 +127,9 @@ Sections organize and expose [entry types](#entry-types) for content authors. In
126127
- Whether entries in the section have URLs;
127128
- What the entries’ URLs should look like;
128129
- Which template should get loaded if an entry’s URL is requested;
130+
- What preview targets are available to authors;
129131
- What [entry types](#entry-types) are available in the section;
130-
- How many authors can be associated with each entry;
132+
- How many authors can be associated with each entry (or disable authors <Since ver="5.7.0" feature="Authorless sections" />);
131133

132134
If your project has multiple [sites](../../system/sites.md), your section can define these additional settings:
133135

@@ -462,6 +464,81 @@ Notifications will appear in the bottom-left corner along with other flashes, an
462464
Automatic merging of changes from canonical entries is nondestructive, and non-optional. Merging occurs just before an entry’s edit screen is viewed.
463465
:::
464466

467+
### Copying Entries <Since ver="5.7.0" feature="Copying entries" />
468+
469+
Entries can be copied and pasted between sections and fields that support the given type(s).
470+
471+
<See path="../../system/elements.md" hash="copying-elements" label="Copying Elements" description="Learn how to copy entries and other elements between contexts." />
472+
473+
## Statuses
474+
475+
In addition to the [base element statuses](../../system/elements.md#statuses), entries may appear in any of these states:
476+
477+
- **Pending** (`pending`) — The **Post Date** is in the future, or not set.
478+
- **Expired** (`expired`) — The **Expiry Date** is set, and in the past.
479+
- **Live** (`live`) — The **Post Date** is in the past, and the **Expiry Date** is in the future (if set at all). This is the default status used in entry queries.
480+
481+
::: tip
482+
Status pips and controls may be hidden from element edit screes, indexes, chips, and cards, if an entry’s type has the **Show the Status field** setting _off_.
483+
:::
484+
485+
When [querying entries by status](../../system/elements.md#querying-by-status), keep in mind that each status identifier in the list above represents multiple conditions. Statuses and their default query conditions help make the appearance or availability of entries consistent between the control panel and front-end; for this reason, params like `.postDate()` and `.expiryDate()` introduce _additional_ constraints, rather than replacing Craft’s. If you need full control over the query constraints, call `.status(null)`.
486+
487+
### Static Statuses <Since ver="5.7.0" feature="Static storage of entry statuses" />
488+
489+
Craft’s powerful [events](../../extend/events.md) system allows developers to react to element updates, and connect author activity and content to other systems. Statuses, however, can be difficult to pin down—entries rely heavily on their **Post Date** and **Expiry Date** attributes to determine when an entry is returned, and what its “status” is at any given time.
490+
491+
Take this query that fetches blog articles:
492+
493+
```twig
494+
{% set posts = craft.entries()
495+
.section('blog')
496+
.all() %}
497+
```
498+
499+
Suppose we have an article with a **Post Date** five minutes in the future. Loading the page with this query _now_ would not display the pending article; if we wait five minutes and refresh the page, the entry _does_ show up… without any intervention by the author! This is because each query compares the server’s current time with entries’ stored `postDate` and `expiryDate` columns; depending on when you look at the data, Craft considers it to be in different statuses. Therein lies the issue: nothing _happens_ when a pending entry “goes live” (or a live entry “expires”), so Craft can’t emit status-change events.
500+
501+
The <config5:staticStatuses> config setting alters this behavior: instead of calculating statuses on-the-fly, Craft stores a static representation of an entry’s status at the time it is saved. Entry queries also use simplified conditions, matching against the stored values instead of date-based comparisons. In this mode, however, entries’ statuses only change when they are saved. The accompanying [`update-statuses` console command](../cli.md#update-statuses) provides a means of routinely checking and re-saving entries:
502+
503+
```bash
504+
ddev craft update-statuses
505+
```
506+
507+
::: warning
508+
If you opt in to static statuses, you must run this command with a tool like [cron](https://en.wikipedia.org/wiki/Cron) to ensure your content is published and expired in a reasonable amount of time.
509+
:::
510+
511+
In a [private plugin](../../extend/plugin-guide.md) or [custom module](../../extend/module-guide.md), you can [listen for save events](kb:handling-entry-saves) and check whether an entry received a new status:
512+
513+
```php
514+
use craft\base\Event;
515+
use craft\elements\Entry;
516+
use craft\events\ModelEvent;
517+
use craft\helpers\ElementHelper;
518+
519+
Event::on(
520+
Entry::class,
521+
Entry::EVENT_AFTER_SAVE,
522+
function (ModelEvent $event) {
523+
/** @var Entry $entry */
524+
$entry = $event->sender;
525+
526+
// Make sure we’re dealing with a canonical entry, and that there was indeed a status change:
527+
if (
528+
!ElementHelper::isDraftOrRevision($entry) &&
529+
$entry->getStatus() !== $entry->oldStatus
530+
) {
531+
if ($entry->getStatus() === Entry::STATUS_LIVE) {
532+
// The entry just moved into the "live" status!
533+
} elseif ($entry->oldStatus === Entry::STATUS_LIVE) {
534+
// The entry *was* live, but isn’t any more!
535+
}
536+
}
537+
});
538+
```
539+
540+
Depending on your editorial process, you will need to adjust the cases here to handle different transitions. Keep in mind that this handler may also run in response to normal entry saves (during an HTTP request) so it is advisable to offload any time- or resource-intensive operations to a [queue job](../../extend/queue-jobs.md).
541+
465542
## Querying Entries
466543

467544
When Craft receives a request matching an entry’s URI, it automatically makes an `entry` variable available. Everywhere else in your front-end (or PHP code), you can fetch entries using **entry queries**.

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

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ There are also **Preferences** for localization, accessibility, and debugging th
3030

3131
All users share a [field layout](../../system/fields.md#field-layouts), which is managed via <Journey path="Settings, Users, User Profile Fields" />. Custom fields are added to the **Profile** tab of each user’s management screen, alongside native **Username**, **Email**, **Full Name**, and **Photo** fields.
3232

33+
Fields and tabs in the user field layout can be given [conditions](../../system/fields.md#conditions) to provide special functionality based on their user group or other criteria.
34+
3335
::: tip
3436
Relate users to other elements with the [users field](../field-types/users.md).
3537
:::

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ related:
1111

1212
Craft has over 20 built-in field types that help create tightly-tailored authoring and developer experiences. The table below lists fields in the same order you’ll encounter them in the [control panel](../../system/control-panel.md); you can also browse them by the [type of data](#data-types) they store.
1313

14+
<!-- more -->
15+
1416
<See path="../system/fields.md" label="Fields + Content" description="Get started with fields in Craft." />
1517

1618
## All Fields
@@ -19,6 +21,7 @@ Craft has over 20 built-in field types that help create tightly-tailored authori
1921
| --- | --- |
2022
| [Addresses](addresses.md) | Manage nested [address](../element-types/addresses.md) elements. |
2123
| [Assets](assets.md) | Relate [asset](../element-types/assets.md) elements. |
24+
| [Button Group](button-group.md) | Choose a single item from a graphical, icon-based toolbar. |
2225
| [Categories](categories.md) | Relate [category](../element-types/categories.md) elements. |
2326
| [Checkboxes](checkboxes.md) | Choose one or more predefined options using `checkbox` inputs. |
2427
| [Color](color.md) | Pick a color with your platform’s native color picker—or provide a hexadecimal value. |
@@ -118,7 +121,7 @@ You can even attach fields to the elements you relate via these fields—metadat
118121

119122
### Media
120123

121-
- [Assets](assets.md) — Upload and attach files anywhere.
124+
- [Assets](assets.md) — Upload and attach files to anything.
122125

123126
### Structured
124127

@@ -137,6 +140,7 @@ Have a complex content model? You can nest entries as deeply as you want!
137140
Spruce up the authoring experience with these dedicated UIs.
138141

139142
- [Color](color.md) — Select from a palette of colors, or choose a new one.
143+
- [Button Group](button-group.md) — Choose from options identified by an icon—great for layout, positioning, and scale controls
140144
- [Icon](icon.md) — Pick from a library of icons.
141145
- [Money](money.md) — Input values in a specific currency.
142146
- [Range](range.md) — Contextualize numeric values.

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

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Address fields are separate from users’ [address book](../element-types/users.
1616
<img src="../../images/fields-addresses.png" alt="Screenshot of addresses field with two nested address elements" />
1717
</BrowserShot>
1818

19+
Addresses can be [copied](../../system/elements.md#copying-elements) between fields, and to or from users’ address books. <Since ver="5.7.0" feature="Copying-and-pasting address elements" />
20+
1921
## Settings
2022

2123
Address fields can be displayed to editors as [cards](../../system/elements.md#chips-cards) or in a full [element index](../../system/elements.md#indexes). Either way, individual addresses are always displayed as cards.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
related:
3+
- uri: radio-buttons.md
4+
label: Radio Button fields
5+
- uri: dropdown.md
6+
label: Dropdown fields
7+
---
8+
9+
# Button Group <Since ver="5.7.0" feature="The button group field" />
10+
11+
Button group fields provide a compact, graphical option for selecting a single value from a list.
12+
13+
<!-- more -->
14+
15+
![Screenshot of the button group field interface in the Craft control panel](../../images/fields-button-group-ui.png)
16+
17+
## Settings
18+
19+
<BrowserShot
20+
url="https://my-craft-project.ddev.site/admin/settings/fields/new"
21+
:link="false"
22+
:max-height="500"
23+
caption="Adding a new button group field via the control panel.">
24+
<img src="../../images/fields-button-group-settings.png" alt="Button group field settings screen in the Craft control panel">
25+
</BrowserShot>
26+
27+
Button group fields have the following settings:
28+
29+
- **Options** — Define any number of options for authors to select from, each with…
30+
- **Label** — A text description of the option. _Labels are hidden when using the **Icons only** setting._
31+
- **Value** — The value stored when a given option is selected.
32+
- **Icon** — Choose from the standard system icon palette.
33+
- **Default?** — One option can be marked as the default.
34+
- **Icons only** — Hide labels in the UI, displaying only the selected icon for each option.
35+
36+
The field works best with a limited number of visually distinct options.
37+
38+
## Development
39+
40+
Button group fields share the same template and query capabilities with [dropdown fields](dropdown.md).

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ Categories fields have the following settings:
3737

3838
- **Min Relations** — The minimum number of categories that must be selected when the field is marked as “required” in a field layout. (Default is no minimum.)
3939
- **Max Relations** — The maximum number of categories that can be selected. (Default is no maximum.)
40+
- **Default Category Placement** — Whether new selections are prepended or appended to the existing relations.
41+
- **View Mode** — How the related users are displayed to authors (_List_ or _Cards_).
4042

41-
- **View Mode** — How the related users are displayed to authors (_List_ or _Cards_).
4243
- **“Add” Button Label** — The label that should be used on the field’s selection button.
4344
- **Validate related categories** — Whether or not validation errors on the related categories will be bubbled up.
4445

0 commit comments

Comments
 (0)