Skip to content

Commit 0f9ac1b

Browse files
committed
Location table attribute for assets
Resolves #11450
1 parent 8148209 commit 0f9ac1b

File tree

7 files changed

+50
-15
lines changed

7 files changed

+50
-15
lines changed

CHANGELOG-WIP.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
- Live Preview now always shows a “Refresh” button, regardless of whether the preview target has auto-refresh enabled. ([#11160](https://github.com/craftcms/cms/discussions/11160))
3737
- Entry Type condition rules now allow multiple selections. ([#11124](https://github.com/craftcms/cms/pull/11124))
3838
- Element index filters now only show condition rules for the custom fields that are used by the field layouts in the selected source, if a native source is selected. ([#11187](https://github.com/craftcms/cms/discussions/11187))
39+
- Asset indexes now have a “Location” table attribute option. ([#11450](https://github.com/craftcms/cms/discussions/11450))
3940
- It’s now possible to sort entries by their section and type. ([#9192](https://github.com/craftcms/cms/discussions/9192), [#11335](https://github.com/craftcms/cms/discussions/11335))
4041
- It’s now possible to sort assets by their file kind.
4142
- Sites’ Language settings now display the locale IDs as option hints, rather than the languages’ native names. ([#11195](https://github.com/craftcms/cms/discussions/11195))

packages/craftcms-sass/_mixins.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,14 +193,14 @@ $radioSize: 16px;
193193
opacity: var(--icon-opacity);
194194
}
195195

196-
@mixin angle($dir: down, $color: currentColor) {
196+
@mixin angle($dir: down, $color: currentColor, $width: 2px) {
197197
display: block;
198198
content: '';
199199
font-size: 0;
200200
width: 7px;
201201
height: 7px;
202202
border: solid $color;
203-
border-width: 0 2px 2px 0;
203+
border-width: 0 $width $width 0;
204204
opacity: 0.8;
205205

206206
@if $dir == up {

src/elements/Asset.php

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,7 @@ protected static function defineTableAttributes(): array
490490
'width' => ['label' => Craft::t('app', 'Image Width')],
491491
'height' => ['label' => Craft::t('app', 'Image Height')],
492492
'alt' => ['label' => Craft::t('app', 'Alternative Text')],
493+
'location' => ['label' => Craft::t('app', 'Location')],
493494
'link' => ['label' => Craft::t('app', 'Link'), 'icon' => 'world'],
494495
'id' => ['label' => Craft::t('app', 'ID')],
495496
'uid' => ['label' => Craft::t('app', 'UID')],
@@ -1992,6 +1993,9 @@ protected function tableAttributeHtml(string $attribute): string
19921993
case 'height':
19931994
$size = $this->$attribute;
19941995
return ($size ? $size . 'px' : '');
1996+
1997+
case 'location':
1998+
return $this->locationHtml();
19951999
}
19962000

19972001
return parent::tableAttributeHtml($attribute);
@@ -2176,16 +2180,8 @@ protected function metaFieldsHtml(bool $static): string
21762180
*/
21772181
protected function metadata(): array
21782182
{
2179-
$volume = $this->getVolume();
2180-
21812183
return [
2182-
Craft::t('app', 'Location') => function() use ($volume) {
2183-
$loc = [Craft::t('site', $volume->name)];
2184-
if ($this->folderPath) {
2185-
array_push($loc, ...ArrayHelper::filterEmptyStringsFromArray(explode('/', $this->folderPath)));
2186-
}
2187-
return implode('', $loc);
2188-
},
2184+
Craft::t('app', 'Location') => fn() => $this->locationHtml(),
21892185
Craft::t('app', 'File size') => function() {
21902186
$size = $this->getFormattedSize(0);
21912187
if (!$size) {
@@ -2213,6 +2209,27 @@ protected function metadata(): array
22132209
];
22142210
}
22152211

2212+
private function locationHtml(): string
2213+
{
2214+
$volume = $this->getVolume();
2215+
$uri = "assets/$volume->handle";
2216+
$items = [
2217+
Html::a(Craft::t('site', $volume->name), UrlHelper::cpUrl($uri)),
2218+
];
2219+
if ($this->folderPath) {
2220+
$subfolders = ArrayHelper::filterEmptyStringsFromArray(explode('/', $this->folderPath));
2221+
foreach ($subfolders as $subfolder) {
2222+
$uri .= "/$subfolder";
2223+
$items[] = Html::a($subfolder, UrlHelper::cpUrl($uri));
2224+
}
2225+
}
2226+
2227+
return Html::ul($items, [
2228+
'encode' => false,
2229+
'class' => 'path',
2230+
]);
2231+
}
2232+
22162233
/**
22172234
* @inheritdoc
22182235
* @since 3.3.0

src/web/assets/cp/dist/css/cp.css

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/web/assets/cp/dist/css/cp.css.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/web/assets/cp/src/css/_cp.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ $systemInfoHoverBgColor: darken($grey800, 10%);
588588
}
589589

590590
&:after {
591-
margin: 0 var(--s);
591+
@include margin(0, 8px, 0, 7px);
592592
@include angle(right, var(--medium-hairline-color));
593593
}
594594
}

src/web/assets/cp/src/css/_main.scss

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,6 +1161,23 @@ td.right {
11611161
@include margin-right(10px);
11621162
}
11631163

1164+
ul.path {
1165+
display: flex;
1166+
flex-direction: row;
1167+
align-items: stretch;
1168+
flex-wrap: wrap;
1169+
1170+
li {
1171+
display: inline-flex;
1172+
align-items: center;
1173+
1174+
&:not(:last-child):after {
1175+
@include margin(0, 5px, 0, 2px);
1176+
@include angle(right, var(--light-text-color), 1px);
1177+
}
1178+
}
1179+
}
1180+
11641181
/* ----------------------------------------
11651182
/* Icon lists
11661183
/* ----------------------------------------*/

0 commit comments

Comments
 (0)