BookStack/app/Entities/Models/EntityContainerData.php
Dan Brown c60052b5e1
Some checks are pending
analyse-php / build (push) Waiting to run
lint-php / build (push) Waiting to run
test-migrations / build (8.2) (push) Waiting to run
test-migrations / build (8.3) (push) Waiting to run
test-migrations / build (8.4) (push) Waiting to run
test-php / build (8.2) (push) Waiting to run
test-php / build (8.3) (push) Waiting to run
test-php / build (8.4) (push) Waiting to run
Entities: Started logic change to new structure
Updated base entity class, and worked through BaseRepo.
Need to go through other repos next.

Removed a couple of redundant interfaces as part of this since we can
move the logic onto the shared ContainerData model as needed.
2025-09-23 16:04:00 +01:00

60 lines
1.5 KiB
PHP

<?php
namespace BookStack\Entities\Models;
use BookStack\Uploads\Image;
use BookStack\Util\HtmlContentFilter;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasOne;
/**
* @property string $description
* @property string $description_html
* @property ?int $default_template_id
* @property ?int $image_id
* @property ?int $sort_rule_id
*/
class EntityContainerData extends Model
{
public $timestamps = false;
/**
* Relation for the cover image for this entity.
* @return HasOne<Image, $this>
*/
public function cover(): HasOne
{
return $this->hasOne(Image::class, 'image_id');
}
/**
* Get the description as a cleaned/handled HTML string.
*/
public function descriptionHtml(bool $raw = false): string
{
$html = $this->description_html ?: '<p>' . nl2br(e($this->description)) . '</p>';
if ($raw) {
return $html;
}
return HtmlContentFilter::removeScriptsFromHtmlString($html);
}
/**
* Update the description from HTML code.
* Optionally takes plaintext to use for the model also.
*/
public function setDescriptionHtml(string $html, string|null $plaintext = null): void
{
$this->description_html = $html;
if ($plaintext !== null) {
$this->description = $plaintext;
}
if (empty($html) && !empty($plaintext)) {
$this->description_html = $this->descriptionHtml();
}
}
}