Correctly set the resource name on empty transformers

This commit is contained in:
Dane Everitt 2021-08-07 15:06:00 -07:00
parent 1bc1b87422
commit 3d14974d64
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53

View file

@ -2,8 +2,8 @@
namespace Pterodactyl\Extensions\Spatie\Fractalistic;
use League\Fractal\TransformerAbstract;
use Spatie\Fractal\Fractal as SpatieFractal;
use Pterodactyl\Transformers\Api\Transformer;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
use Pterodactyl\Extensions\League\Fractal\Serializers\PterodactylSerializer;
@ -33,12 +33,9 @@ class Fractal extends SpatieFractal
// If the resource name is not set attempt to pull it off the transformer
// itself and set it automatically.
if (
is_null($this->resourceName)
&& $this->transformer instanceof TransformerAbstract
&& method_exists($this->transformer, 'getResourceName')
) {
$this->resourceName = $this->transformer->getResourceName();
$class = is_string($this->transformer) ? new $this->transformer : $this->transformer;
if (is_null($this->resourceName) && $class instanceof Transformer) {
$this->resourceName = $class->getResourceName();
}
return parent::createData();