Skip to content

Commit 85eea84

Browse files
committed
Element statuses, etc.
1 parent 6a90538 commit 85eea84

File tree

1 file changed

+54
-10
lines changed

1 file changed

+54
-10
lines changed

docs/5.x/system/elements.md

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,12 @@ A copied [draft](drafts-revisions.md) (provisional or otherwise) is pasted as a
178178

179179
## Statuses
180180

181-
Most element types support _statuses_. An element’s status is most often a combination of its `enabled` and `enabledForSite` attributes (which Craft stores explicitly for all elements), and any number of other attributes determined by its type. Statuses are represented as strings, and can be accessed via `element.status` in a template, or fed into element query’s `.status()` param as a short-hand for the combination of specific properties they represent.
181+
Most element types support _statuses_. An element’s status is most often a combination of its `enabled` and `enabledForSite` attributes (which Craft stores explicitly for all elements), and any number of other attributes determined by its [type](#element-types). Statuses are represented as strings, and can be accessed via `element.status` in a template, or fed into element query’s `.status()` param as a short-hand for the combination of specific properties they represent.
182182

183183
- **Draft** (`draft`) — The element has a `draftId`.
184184
- **Archived** (`archived`) — The element’s `archived` property is `true`; currently only used by [user](../reference/element-types/users.md) elements.
185185
- **Disabled** (`disabled`) — One or both of the `enabled` and `enabledForSite` attributes are `false`.
186-
- **Enabled** — Both the `enabled` _and_ `enabledForSite` attributes are `true`.
186+
- **Enabled** (`enabled`) — Both the `enabled` _and_ `enabledForSite` attributes are `true`.
187187

188188
::: tip
189189
To query for elements without applying _any_ status constraints (including the element type’s defaults), use `query.status(null)`.
@@ -201,7 +201,53 @@ Conversely, disabling an element in a provisional draft may make it _appear_ as
201201

202202
</Block>
203203

204-
## Nested Elements
204+
### Querying by Status
205+
206+
When querying for elements using the `.status()` param, you’ll need to refer to the list of global identifiers above, and to additional statuses provided by the specific element type:
207+
208+
```twig{3,9,15}
209+
{% set currentDeals = craft.entries()
210+
.section('deals')
211+
.status('live')
212+
.order('postDate DESC')
213+
.all() %}
214+
215+
{% set upcomingDeals = craft.entries()
216+
.section('deals')
217+
.status('pending')
218+
.order('postDate ASC')
219+
.all() %}
220+
221+
{% set pastDeals = craft.entries()
222+
.section('deals')
223+
.status('expired')
224+
.order('expiryDate DESC')
225+
.all() %}
226+
```
227+
228+
Statuses can be logically combined in a single query, as well:
229+
230+
```twig
231+
{# Two explicit statuses: #}
232+
{% set bannedUsers = craft.users()
233+
.status([
234+
'suspended',
235+
'locked',
236+
])
237+
.all() %}
238+
239+
{# One explicit status: #}
240+
{% set inactiveUsers = craft.users()
241+
.status('inactive')
242+
.all() %}
243+
244+
{# Negated/inverted status: #}
245+
{% set inactiveUsersAlt = craft.users()
246+
.status(['not', 'active'])
247+
.all() %}
248+
```
249+
250+
## Nested Elements <Badge text="New!" />
205251

206252
Craft ships with two native _nested element_ implementations, which provide unique authoring or administrative experiences:
207253

@@ -314,11 +360,9 @@ When accessing related or nested content within an element partial, use the `.ea
314360

315361
## Properties and Methods
316362

317-
<Todo notes="Move to elements reference?" />
318-
319363
All elements share a few characteristics that make them familiar to work with in your [templates](../development/templates.md). Each [element type](#element-types) will supplement these lists with their own properties and methods.
320364

321-
Additionally, [custom fields](fields.md) attached to an element are automatically made available as properties corresponding to their handles—so a field called “Post Summary” with a handle of `summary` would be accessed as `entry.summary` (if it were attached to an [entry type](../reference/element-types/entries.md#entry-types)’s field layout).
365+
Additionally, [custom fields](fields.md) attached to an element are automatically made available as properties corresponding to their handles—so a field called “Post Summary” with a handle of `summary` would be accessed as `entry.summary` (if it were attached to an [entry type](../reference/element-types/entries.md#entry-types)’s field layout, and its handle was not overridden).
322366

323367
::: warning
324368
This is not an exhaustive list! If you’re curious, consult the <craft5:craft\base\Element> and <craft5:craft\base\ElementTrait> class reference for a complete picture of what data is available inside elements and how it can be used.
@@ -329,7 +373,7 @@ This is not an exhaustive list! If you’re curious, consult the <craft5:craft\b
329373
Properties give you access to values, and do not accept arguments.
330374

331375
Property | Type | Notes
332-
-------- | ---- | -----
376+
--- | --- | ---
333377
`archived` | `bool|null` | Whether the element is soft-deleted, or “trashed.”
334378
`dateCreated` | `DateTime` | Date the element was originally created.
335379
`dateDeleted` | `DateTime|null` | Date the element was soft-deleted or `null` if not.
@@ -352,11 +396,11 @@ Property | Type | Notes
352396
Methods also return values, but may accept or require arguments.
353397

354398
::: tip
355-
Any method beginning with `get` can be used like a [property](#properties) by removing the prefix and down-casing the first letter. For example, `{{ entry.getLink() }}` can also be accessed as `{{ entry.link }}`
399+
Any method beginning with `get` (and that accepts no arguments) can be used like a [property](#properties) by removing the prefix and down-casing the first letter. For example, `{{ entry.getLink() }}` can also be used as `{{ entry.link }}` in a template. This is referred to as a “getter” or “magic getter,” and works in part due to the [design of Yii](guide:concept-properties), Craft’s underlying PHP library.
356400
:::
357401

358402
Method | Notes
359-
------ | -----
403+
--- | ---
360404
`getAncestors(dist)` | Returns up to `dist` parents of the element, or all parents when omitted. _Structures only._
361405
`getChildren()` | Returns immediate children of the element. _Structures only._
362406
`getCpEditUrl()` | Gets a URL to the Craft control panel.
@@ -367,7 +411,7 @@ Method | Notes
367411
`getNext(criteria)` | Load the “next” element relative to this one, given a set of criteria.
368412
`getNextSibling()` | Load the next sibling of this element, within a structure. _Structures only._
369413
`getOwner()` | Return the element that “owns” a [nested element](../reference/element-types/entries.md#nested-entries). _Nested elements only._
370-
`getParent()` | Returns the element’s parent. _Structures only._
414+
`getParent()` | Returns the element’s parent. _Structure elements only._
371415
`getPrev(criteria)` | Load the previous element relative to this one, given a set of criteria.
372416
`getPrevSibling()` | Load the previous sibling of this element, within a structure. _Structures only._
373417
`getRef()` | Builds the part of a [reference tag](reference-tags.md) unique to the element.

0 commit comments

Comments
 (0)