Skip to content

Commit

Permalink
site--x classes
Browse files Browse the repository at this point in the history
Resolves #11082
Resolves #11303
  • Loading branch information
brandonkelly committed May 24, 2022
1 parent 09b2b27 commit 77f87cc
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,9 +2,13 @@

## Unreleased

### Added
- Added `craft\web\twig\variables\Cp::getRequestedSite()`. ([#11082](https://github.com/craftcms/cms/discussions/11082))

### Changed
- `temp` is now a reserved volume handle.
- Improved the performance of field layout designers. ([#11298](https://github.com/craftcms/cms/issues/11298))
- All control panel pages now have a `site--<siteHandle>` class name on the `<body>`, based on the currently-selected site. ([#11303](https://github.com/craftcms/cms/discussions/11303))

### Fixed
- Fixed a bug where it wasn’t possible to disable all table columns for an element source. ([#11291](https://github.com/craftcms/cms/issues/11291))
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/GlobalsController.php
Expand Up @@ -175,7 +175,7 @@ public function actionEditContent(string $globalSetHandle, ?GlobalSet $globalSet

// Render the template!
return $this->renderTemplate('globals/_edit', [
'bodyClass' => 'edit-global-set site--' . $site->handle,
'bodyClass' => 'edit-global-set',
'editableGlobalSets' => $editableGlobalSets,
'globalSet' => $globalSet,
'tabs' => $form->getTabMenu(),
Expand Down
2 changes: 2 additions & 0 deletions src/templates/_layouts/base.twig
Expand Up @@ -2,12 +2,14 @@
{% set docTitle = docTitle is defined ? docTitle : title|striptags -%}
{% set orientation = craft.app.locale.getOrientation() -%}
{% set a11yDefaults = craft.app.config.general.accessibilityDefaults %}
{% set requestedSite = craft.cp.requestedSite %}

{% set bodyClass = (bodyClass ?? [])|explodeClass|merge([
orientation,
not (currentUser.getPreference('alwaysShowFocusRings') ?? a11yDefaults['alwaysShowFocusRings'] ?? false) ? 'reduce-focus-visibility',
(currentUser.getPreference('useShapes') ?? a11yDefaults['useShapes'] ?? false) ? 'use-shapes',
(currentUser.getPreference('underlineLinks') ?? a11yDefaults['underlineLinks'] ?? false) ? 'underline-links',
requestedSite ? "site--#{requestedSite.handle}",
])|filter -%}

{% set bodyAttributes = {
Expand Down
2 changes: 1 addition & 1 deletion src/web/assets/cp/dist/cp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/cp/dist/cp.js.map

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions src/web/assets/cp/src/js/CP.js
Expand Up @@ -1330,6 +1330,14 @@ Craft.CP = Garnish.Base.extend(
const url = Craft.getUrl(document.location.href, {site: site.handle});
history.replaceState({}, '', url);

// update the site--x body class
for (className of document.body.classList) {
if (className.match(/^site--/)) {
document.body.classList.remove(className);
}
}
document.body.classList.add(`site--${site.handle}`);

// update other URLs on the page
$('a').each(function () {
if (
Expand Down
12 changes: 12 additions & 0 deletions src/web/twig/variables/Cp.php
Expand Up @@ -19,6 +19,7 @@
use craft\helpers\StringHelper;
use craft\helpers\UrlHelper;
use craft\models\FieldLayout;
use craft\models\Site;
use craft\models\Volume;
use craft\web\twig\TemplateLoaderException;
use DateTime;
Expand Down Expand Up @@ -139,6 +140,17 @@ class Cp extends Component
*/
public const EVENT_REGISTER_CP_SETTINGS = 'registerCpSettings';

/**
* Returns the site the control panel is currently working with, via a `site` query string param if sent.
*
* @return Site|null The site, or `null` if the user doesn’t have permission to edit any sites.
* @since 4.0.4
*/
public function getRequestedSite(): ?Site
{
return CpHelper::requestedSite();
}

/**
* Returns the Craft ID account URL.
*
Expand Down

0 comments on commit 77f87cc

Please sign in to comment.