Skip to content

Commit f1fbd32

Browse files
committed
Merge branch '2025.4' into 2026.x
2 parents 3db77cc + 1728c17 commit f1fbd32

2 files changed

Lines changed: 19 additions & 9 deletions

File tree

src/Icon/Service/IconService.php

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,14 @@ public function getIconForTag(): string
121121
return 'tag';
122122
}
123123

124-
public function getIconForClassDefinition(?string $iconPath): ElementIcon
124+
public function getIconForClassDefinition(?string $value): ElementIcon
125125
{
126-
$type = ElementIconTypes::PATH->value;
127126
// $iconPath can be null and empty string
128-
if (empty($iconPath)) {
129-
$type = ElementIconTypes::NAME->value;
130-
$iconPath = 'class';
127+
if (empty($value)) {
128+
return new ElementIcon(ElementIconTypes::NAME->value, 'class');
131129
}
132130

133-
return new ElementIcon($type, $iconPath);
131+
return new ElementIcon($this->guessIconType($value), $value);
134132
}
135133

136134
public function getIconForLayout(?string $iconPath): ?ElementIcon
@@ -157,14 +155,26 @@ private function getClassIcon(DataObjectSearchResultItem|DataObject $dataObject)
157155
if ($dataObject instanceof Concrete) {
158156
$class = $this->getValidClass($this->classDefinitionResolver, $dataObject->getClassId());
159157
if ($class->getIcon() !== null) {
160-
return new ElementIcon(ElementIconTypes::PATH->value, $class->getIcon());
158+
return new ElementIcon($this->guessIconType($class->getIcon()), $class->getIcon());
161159
}
162160
}
163161

164162
if ($dataObject->getClassDefinitionIcon() !== null) {
165-
return new ElementIcon(ElementIconTypes::PATH->value, $dataObject->getClassDefinitionIcon());
163+
return new ElementIcon(
164+
$this->guessIconType($dataObject->getClassDefinitionIcon()),
165+
$dataObject->getClassDefinitionIcon()
166+
);
166167
}
167168

168169
return null;
169170
}
171+
172+
private function guessIconType(string $value): string
173+
{
174+
if (str_contains($value, '/') && str_contains($value, '.')) {
175+
return ElementIconTypes::PATH->value;
176+
}
177+
178+
return ElementIconTypes::NAME->value;
179+
}
170180
}

src/Icon/Service/IconServiceInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function getIconForDocument(string $documentType): ElementIcon;
3030

3131
public function getIconForTag(): string;
3232

33-
public function getIconForClassDefinition(?string $iconPath): ElementIcon;
33+
public function getIconForClassDefinition(?string $value): ElementIcon;
3434

3535
public function getIconForLayout(?string $iconPath): ?ElementIcon;
3636

0 commit comments

Comments
 (0)