init
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Esun\MultiLocaleTranslation\Model;
|
||||
|
||||
class BlogPostFields
|
||||
{
|
||||
public const FIELDS = [
|
||||
'name' => ['label' => 'Post Name', 'is_html' => false],
|
||||
'short_description' => ['label' => 'Short Description', 'is_html' => true],
|
||||
'post_content' => ['label' => 'Content', 'is_html' => true],
|
||||
'meta_title' => ['label' => 'Meta Title', 'is_html' => false],
|
||||
'meta_keywords' => ['label' => 'Meta Keywords', 'is_html' => false],
|
||||
'meta_description' => ['label' => 'Meta Description', 'is_html' => false],
|
||||
];
|
||||
|
||||
public static function codes(): array
|
||||
{
|
||||
return array_keys(self::FIELDS);
|
||||
}
|
||||
|
||||
public static function baseValue(string $field, mixed $value): string
|
||||
{
|
||||
$value = is_string($value) ? $value : (string)($value ?? '');
|
||||
if (!in_array($field, ['meta_title', 'meta_keywords', 'meta_description'], true)) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
$decoded = json_decode($value, true);
|
||||
if (json_last_error() !== JSON_ERROR_NONE || !is_array($decoded)) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
return (string)($decoded[0] ?? $decoded['0'] ?? '');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user