Skip to content

Commit

Permalink
Merge branch '6.0' into 6
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Feb 24, 2025
2 parents 6216e52 + bb01dd9 commit 76c705c
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 4 deletions.
33 changes: 33 additions & 0 deletions en/02_Developer_Guides/00_Model/10_Versioning.md
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,15 @@ $stageRecord = Versioned::get_by_stage(MyRecord::class, Versioned::DRAFT)->byID(
$liveRecord = Versioned::get_by_stage(MyRecord::class, Versioned::LIVE)->byID(99);
```

If you already have a list and want to filter it to only include records in a given stage, you can use [`updateListToAlsoIncludeStage()`](api:SilverStripe\Versioned\Versioned::updateListToAlsoIncludeStage()) instead.

```php
use SilverStripe\Versioned\Versioned;
$myList = MyRecord::get()->filter(['Name' => 'Example']);
$stageRecords = Versioned::updateListToAlsoIncludeStage($myList, Versioned::DRAFT);
```

You can also use [`Versioned::withVersionedMode()`](api:SilverStripe\Versioned\Versioned::withVersionedMode()) in conjunction with [`Versioned::set_stage()`](api:SilverStripe\Versioned\Versioned::set_stage()) to temporarily change what stage is being used for queries.

```php
Expand Down Expand Up @@ -665,6 +674,30 @@ $versions = $record->allVersions();
$version = $versions->First()->Version;
```

### Reading archived versions

Similarly to using `Versioned::get_by_stage()` and `Versioned::updateListToAlsoIncludeStage()` to get versions of records in a particular stage, you can also fetch records that have been archived.

There are a few different methods for this, depending on exactly what information you're after:

- [`getRemovedFromDraft()`](api:SilverStripe\Versioned\Versioned::getRemovedFromDraft()) - Returns a new list of records (both published and archived) which have been removed from draft.
- [`updateListToOnlyIncludeRemovedFromDraft()`](api:SilverStripe\Versioned\Versioned::updateListToOnlyIncludeRemovedFromDraft()) - Gives the same results as `getRemovedFromDraft()`, but you can pass it a list to modify instead of it giving you a new list.
- [`getArchivedOnly()`](api:SilverStripe\Versioned\Versioned::getArchivedOnly()) - Returns a new list of only records which have been archived. This excludes records which are published but removed from draft.
- [`updateListToOnlyIncludeArchived()`](api:SilverStripe\Versioned\Versioned::updateListToOnlyIncludeArchived()) - Gives the same results as `getArchivedOnly()`, but you can pass it a list to modify instead of it giving you a new list.

```php
use SilverStripe\Versioned\Versioned;

// Fetching a new list
$archivedAndOnlyLive = Versioned::getRemovedFromDraft(MyRecord::class);
$ArchivedOnly = Versioned::getArchivedOnly(MyRecord::class);

// Using an existing list
$myList = MyRecord::get()->filter(['Name' => 'Example']);
$archivedAndOnlyLive = Versioned::updateListToOnlyIncludeRemovedFromDraft($myList);
$ArchivedOnly = Versioned::updateListToOnlyIncludeArchived($myList);
```

### Writing changes to a versioned `DataObject`

When you call the `write()` method on a versioned `DataObject` record, this will transparently create a new version of the record in the "Stage" stage.
Expand Down
8 changes: 4 additions & 4 deletions en/02_Developer_Guides/09_Security/04_Sudo_Mode.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,7 @@ specific react component.
> [!WARNING]
> Sudo mode for react components does not protect the data the component manages, or any endpoints the component uses, it simply requires the user to re-enter their password before the component is rendered.

> [!IMPORTANT]
> The `WithSudoMode` HOC is exposed via [Webpack's expose-loader plugin](https://webpack.js.org/loaders/expose-loader/). You will need to add it as a [webpack external](https://webpack.js.org/configuration/externals/) to use it. The recommended way to do this is via the [@silverstripe/webpack-config npm package](https://www.npmjs.com/package/@silverstripe/webpack-config) which handles all the external configuration for you.

You can get the injector to apply the HOC to your component automatically using [injector transformations](/developer_guides/customising_the_admin_interface/reactjs_and_redux/#transforming-services-using-middleware):
You can get the injector to apply the HOC to your component automatically using [injector transformations](/developer_guides/customising_the_admin_interface/reactjs_redux_and_graphql/#transforming-services-using-middleware):

```js
import WithSudoMode from 'containers/SudoMode/SudoMode';
Expand All @@ -107,6 +104,9 @@ Injector.transform('MyComponentWithSudoMode', (updater) => {
});
```

> [!IMPORTANT]
> The `WithSudoMode` HOC is exposed via [Webpack's expose-loader plugin](https://webpack.js.org/loaders/expose-loader/). You will need to add it as a [webpack external](https://webpack.js.org/configuration/externals/) to use it. The recommended way to do this is via the [@silverstripe/webpack-config npm package](https://www.npmjs.com/package/@silverstripe/webpack-config) which handles all the external configuration for you.

If the user has already activated sudo mode and it has not expired, they can interact with your component automatically. Otherwise, they will need to verify their identity by re-entering their password.

![Sudo mode HOC example](../../_images/sudomode.png)
Expand Down
12 changes: 12 additions & 0 deletions en/08_Changelogs/6.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ title: 6.0.0 (unreleased)
- [Changes to `LeftAndMain` and its subclasses](#leftandmain-refactor)
- [Changes to password validation](#password-validation)
- [Status flags in the CMS](#status-flags-in-the-cms)
- [New `Versioned` methods](#new-versioned-methods)
- [New default front-end theme](#theme)
- [Other new features](#other-new-features)
- [Dependency changes](#dependency-changes)
Expand Down Expand Up @@ -839,6 +840,17 @@ Status flags are displayed in breadcrumbs at the top of edit forms in the CMS, i

See [status flags](/developer_guides/customising_the_admin_interface/status_flags/) for more information.

### New `Versioned` methods

The following new methods have been added to [`Versioned`](api:SilverStripe\Versioned\Versioned) to make it easier to get records in the various versioning states:

- [`updateListToAlsoIncludeStage()`](api:SilverStripe\Versioned\Versioned::updateListToAlsoIncludeStage()) - Gives the same results as [`get_by_stage()`](api:SilverStripe\Versioned\Versioned::get_by_stage()), but you can pass it a list to modify instead of it giving you a new list.
- [`updateListToAlsoIncludeDeleted()`](api:SilverStripe\Versioned\Versioned::updateListToAlsoIncludeDeleted()) - Gives the same results as [`get_including_deleted()`](api:SilverStripe\Versioned\Versioned::get_including_deleted()), but you can pass it a list to modify instead of it giving you a new list.
- [`getRemovedFromDraft()`](api:SilverStripe\Versioned\Versioned::getRemovedFromDraft()) - Returns a list of records (both published and archived) which have been removed from draft.
- [`updateListToOnlyIncludeRemovedFromDraft()`](api:SilverStripe\Versioned\Versioned::updateListToOnlyIncludeRemovedFromDraft()) - Gives the same results as `getRemovedFromDraft()`, but you can pass it a list to modify instead of it giving you a new list.
- [`getArchivedOnly()`](api:SilverStripe\Versioned\Versioned::getArchivedOnly()) - Returns a list of only records which have been archived.
- [`updateListToOnlyIncludeArchived()`](api:SilverStripe\Versioned\Versioned::updateListToOnlyIncludeArchived()) - Gives the same results as `getArchivedOnly()`, but you can pass it a list to modify instead of it giving you a new list.

### New default front-end theme {#theme}

New projects created using `silverstripe/installer` will notice a new theme [`silverstripe/startup-theme`](https://packagist.org/packages/silverstripe/startup-theme) which replaces `silverstripe-themes/simple`.
Expand Down

0 comments on commit 76c705c

Please sign in to comment.