Skip to content

Commit be6b398

Browse files
committed
add support for egg variables, closes pterodactyl#974
1 parent 620c624 commit be6b398

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
77
### Fixed
88
* Fixes an exception thrown when trying to access the `/nests/:id/eggs/:id` API endpoint.
99

10+
### Added
11+
* Adds ability to include egg variables on an API request.
12+
1013
## v0.7.1 (Derelict Dermodactylus)
1114
### Fixed
1215
* Fixes an exception when no token is entered on the 2-Factor enable/disable page and the form is submitted.

app/Transformers/Api/Application/EggTransformer.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Pterodactyl\Models\Egg;
66
use Pterodactyl\Models\Nest;
77
use Pterodactyl\Models\Server;
8+
use Pterodactyl\Models\EggVariable;
89
use Pterodactyl\Services\Acl\Api\AdminAcl;
910

1011
class EggTransformer extends BaseTransformer
@@ -15,7 +16,7 @@ class EggTransformer extends BaseTransformer
1516
* @var array
1617
*/
1718
protected $availableIncludes = [
18-
'nest', 'servers', 'config', 'script',
19+
'nest', 'servers', 'config', 'script', 'variables',
1920
];
2021

2122
/**
@@ -147,4 +148,25 @@ public function includeScript(Egg $model)
147148
];
148149
});
149150
}
151+
152+
/**
153+
* Include the variables that are defined for this Egg.
154+
*
155+
* @param \Pterodactyl\Models\Egg $model
156+
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
157+
*/
158+
public function includeVariables(Egg $model)
159+
{
160+
if (! $this->authorize(AdminAcl::RESOURCE_EGGS)) {
161+
return $this->null();
162+
}
163+
164+
$model->loadMissing('variables');
165+
166+
return $this->collection(
167+
$model->getRelation('variables'),
168+
$this->makeTransformer(EggVariableTransformer::class),
169+
EggVariable::RESOURCE_NAME
170+
);
171+
}
150172
}

0 commit comments

Comments
 (0)