Skip to content
This repository was archived by the owner on Oct 13, 2025. It is now read-only.

Commit 1976bd3

Browse files
committed
Add new methods for Displayed
1 parent 10e9540 commit 1976bd3

File tree

1 file changed

+33
-5
lines changed

1 file changed

+33
-5
lines changed

code/DataListExtension.php

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,38 @@
55
*
66
* @property DataList owner
77
*/
8-
class DataListExtension extends Extension {
8+
class DataListExtension extends Extension
9+
{
910

10-
public function ListColumn($column, $glue = ', '){
11-
return implode($glue, $this->owner->column($column));
12-
}
11+
public function ListColumn($column, $glue = ', ')
12+
{
13+
return implode($glue, $this->owner->column($column));
14+
}
1315

14-
}
16+
public function Displayed($visible = true)
17+
{
18+
$list = clone $this->owner;
19+
20+
return $list->filter('Displayed', $visible);
21+
}
22+
23+
public function OnlyVisible()
24+
{
25+
return $this->Displayed(true);
26+
}
27+
28+
public function OnlyHidden()
29+
{
30+
return $this->Displayed(false);
31+
}
32+
33+
public function WithVisible($relation)
34+
{
35+
$list = clone $this->owner;
36+
37+
return $list->filterByCallback(function ($obj) use ($relation) {
38+
return $obj->{$relation}()->OnlyVisible()->exists();
39+
});
40+
}
41+
42+
}

0 commit comments

Comments
 (0)