Commit 34be5bcc authored by Yassine Doghri's avatar Yassine Doghri
Browse files

refactor(plugins): create Field objects per field type in settings forms +...

refactor(plugins): create Field objects per field type in settings forms + handle rendering in class

update manifest.schema.json to have defaultValue type differ based on field type
parent d3a98db6
Loading
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -19,6 +19,8 @@ class DropDeprecatedPodcastsFields extends BaseMigration
    #[Override]
    public function up(): void
    {
        // TODO: migrate data

        $this->forge->dropColumn(
            'podcasts',
            'episode_description_footer_markdown,episode_description_footer_html,is_owner_email_removed_from_feed,medium,payment_pointer,verify_txt,custom_rss,partner_id,partner_link_url,partner_image_url'
+11 −5
Original line number Diff line number Diff line
@@ -55,7 +55,7 @@ use RuntimeException;
 * @property string $language_code
 * @property int $category_id
 * @property Category|null $category
 * @property string $other_categories_ids
 * @property int[] $other_categories_ids
 * @property Category[] $other_categories
 * @property string|null $parental_advisory
 * @property string|null $publisher
@@ -111,7 +111,10 @@ class Podcast extends Entity
     */
    protected ?array $other_categories = null;

    protected string $other_categories_ids = '';
    /**
     * @var int[]
     */
    protected array $other_categories_ids = [];

    /**
     * @var Episode[]|null
@@ -523,10 +526,13 @@ class Podcast extends Entity
        return $this->other_categories;
    }

    public function getOtherCategoriesIds(): string
    /**
     * @return int[]
     */
    public function getOtherCategoriesIds(): array
    {
        if ($this->other_categories_ids === '') {
            $this->other_categories_ids = implode(',', array_column($this->getOtherCategories(), 'id'));
        if ($this->other_categories_ids === []) {
            $this->other_categories_ids = array_column($this->getOtherCategories(), 'id');
        }

        return $this->other_categories_ids;
+5 −0
Original line number Diff line number Diff line
@@ -21,4 +21,9 @@ class OtherRules
    {
        return is_array($str);
    }

    public function is_string_or_list(mixed $str = null): bool
    {
        return is_string($str) || is_array($str);
    }
}
+1 −4
Original line number Diff line number Diff line
@@ -10,12 +10,9 @@ class CodeEditor extends FormComponent
{
    protected array $props = ['content', 'lang'];

    /**
     * @var array<string, string>
     */
    protected array $attributes = [
        'rows'  => '6',
        'class' => 'textarea',
        'class' => 'bg-elevated w-full rounded-lg border-3 border-contrast focus:border-contrast focus-within:ring-accent transition',
    ];

    protected string $lang = '';
+18 −4
Original line number Diff line number Diff line
@@ -26,9 +26,15 @@ abstract class FormComponent extends Component

    protected string $name;

    protected string $value = '';
    /**
     * @var string|string[]|null
     */
    protected string|array|null $value = null;

    protected string $defaultValue = '';
    /**
     * @var string|string[]
     */
    protected string|array $defaultValue = '';

    protected bool $isRequired = false;

@@ -61,8 +67,16 @@ abstract class FormComponent extends Component
        }
    }

    protected function getValue(): string
    protected function getValue(): string|array
    {
        return old($this->name, $this->value === '' ? $this->defaultValue : $this->value);
        $valueCast = $this->casts['value'] ?? '';
        if ($valueCast === 'array') {
            return old($this->name, in_array($this->value, [[], null], true) ? $this->defaultValue : $this->value) ?? [];
        }

        return old(
            $this->name,
            in_array($this->value, ['', null], true) ? $this->defaultValue : $this->value
        ) ?? '';
    }
}
Loading