mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-07-11 01:24:46 +02:00
0fc9fd832c
* refactor(api): mark fields as renderable for display to the user with custom logic * style: fix StyleCI findings
53 lines
1.2 KiB
PHP
53 lines
1.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Api\Field\Wiki\Video\Script;
|
|
|
|
use App\Contracts\Http\Api\Field\RenderableField;
|
|
use App\Http\Api\Field\Field;
|
|
use App\Http\Api\Query\ReadQuery;
|
|
use App\Http\Api\Schema\Schema;
|
|
use App\Http\Resources\Wiki\Video\Resource\ScriptResource;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
/**
|
|
* Class ScriptLinkField.
|
|
*/
|
|
class ScriptLinkField extends Field implements RenderableField
|
|
{
|
|
/**
|
|
* Create a new field instance.
|
|
*
|
|
* @param Schema $schema
|
|
*/
|
|
public function __construct(Schema $schema)
|
|
{
|
|
parent::__construct($schema, ScriptResource::ATTRIBUTE_LINK);
|
|
}
|
|
|
|
/**
|
|
* Determine if the field should be displayed to the user.
|
|
*
|
|
* @param ReadQuery $query
|
|
* @return bool
|
|
*/
|
|
public function shouldRender(ReadQuery $query): bool
|
|
{
|
|
$criteria = $query->getFieldCriteria($this->schema->type());
|
|
|
|
return $criteria === null || $criteria->isAllowedField($this->getKey());
|
|
}
|
|
|
|
/**
|
|
* Get the value to display to the user.
|
|
*
|
|
* @param Model $model
|
|
* @return string
|
|
*/
|
|
public function render(Model $model): string
|
|
{
|
|
return route('videoscript.show', $model);
|
|
}
|
|
}
|