Skip to content

Commit

Permalink
DOC Stop using Controller::has_curr() (#693)
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz authored Feb 16, 2025
1 parent 33ae51f commit 022e79e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -436,12 +436,12 @@ class ProductPage extends Page
public function MetaTags($includeTitle = true)
{
$tags = parent::MetaTags($includeTitle);
if (!Controller::has_curr()) {
$controller = Controller::curr();
if ($controller === null) {
return;
}
// If the 'DataObjectPreview' GET parameter is present, remove 'x-page-id' and 'x-cms-edit-link' meta tags.
// This ensures that toggling between draft/published states doesn't revert the CMS to the page's edit form.
$controller = Controller::curr();
$request = $controller->getRequest();
if ($request->getVar('DataObjectPreview') !== null) {
$html = HTMLValue::create($tags);
Expand Down
5 changes: 5 additions & 0 deletions en/08_Changelogs/6.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ title: 6.0.0 (unreleased)
- [Most extension hook methods are now protected](#hooks-protected)
- [Changes to some extension hook names](#hooks-renamed)
- [`FormField::Value()` split into two methods](#formfield-value)
- [`Controller::has_curr()` removed](#controller-has-curr)
- [Strict typing for `Factory` implementations](#factory-strict-typing)
- [Elemental `TopPage` class names changed](#elemental-top-page)
- [List interface changes](#list-interface-changes)
Expand Down Expand Up @@ -1051,6 +1052,10 @@ If you have implemented any of those methods in an [`Extension`](api:SilverStrip

If you have overridden the `Value()` method in a subclass, you will need to update the method name to one of these, depending on the purpose of the custom functionality. If you use `$Value` in a template to get the value of a form field, you will need to update it to `$FormattedValue`.

### `Controller::has_curr()` removed {#controller-has-curr}

The `SilverStripe\Control\Controller::has_curr()` method has been removed. If you were using this method in your project then you should replace it with a call to [`Controller::curr()`](api:SilverStripe\Control\Controller::curr()) and checking if it returned `null`, meaning if there is no current controller. This is equivalent to checking if `has_curr()` had returned `false`. `Controller::curr()` no longer creates an exception if there is no current controller.

### Strict typing for `Factory` implementations {#factory-strict-typing}

The [`Factory::create()`](api:SilverStripe\Core\Injector\Factory::create()) method now has strict typehinting. The first argument must be a string, and either `null` or an object must be returned.
Expand Down

0 comments on commit 022e79e

Please sign in to comment.