Commit 45ac2a4b authored by Yassine Doghri's avatar Yassine Doghri
Browse files

feat(plugins): handle empty states and long strings in UI

parent b62b483a
Loading
Loading
Loading
Loading
+11 −4
Original line number Diff line number Diff line
@@ -125,8 +125,15 @@ class PluginController extends BaseController
            $data['episode'] = $episode;
        }

        $fields = $plugin->getSettingsFields($type);

        if ($fields === []) {
            throw PageNotFoundException::forPageNotFound();
        }

        $data['type'] = $type;
        $data['context'] = $context;
        $data['fields'] = $fields;

        helper('form');
        replace_breadcrumb_params($breadcrumbReplacements);
@@ -164,8 +171,8 @@ class PluginController extends BaseController
        $rules = [];
        foreach ($plugin->getSettingsFields($type) as $field) {
            $typeRules = $plugins::FIELDS_VALIDATIONS[$field->type];
            if (! in_array('permit_empty', $typeRules, true) && ! $field->optional) {
                $typeRules[] = 'required';
            if (! in_array('permit_empty', $typeRules, true)) {
                $typeRules[] = $field->optional ? 'permit_empty' : 'required';
            }

            $rules[$field->key] = $typeRules;
@@ -182,7 +189,7 @@ class PluginController extends BaseController

        foreach ($plugin->getSettingsFields('general') as $field) {
            $value = $validatedData[$field->key] ?? null;
            $fieldValue = match ($plugins::FIELDS_CASTS[$field->type] ?? 'text') {
            $fieldValue = $value === '' ? null : match ($plugins::FIELDS_CASTS[$field->type] ?? 'text') {
                'bool'     => $value === 'yes',
                'int'      => (int) $value,
                'uri'      => new URI($value),
@@ -192,7 +199,7 @@ class PluginController extends BaseController
                    $this->request->getPost('client_timezone')
                )->setTimezone(app_timezone()),
                'markdown' => new Markdown($value),
                default    => $value === '' ? null : $value,
                default    => $value,
            };
            $plugins->setOption($plugin, $field->key, $fieldValue, $context);
        }
+9 −6
Original line number Diff line number Diff line
@@ -108,11 +108,6 @@ abstract class BasePlugin implements PluginInterface
        return in_array($name, $this->manifest->hooks, true);
    }

    final public function getSettings(): ?Settings
    {
        return $this->manifest->settings;
    }

    final public function getVersion(): string
    {
        return $this->manifest->version;
@@ -167,7 +162,7 @@ abstract class BasePlugin implements PluginInterface
     */
    final public function getSettingsFields(string $type): array
    {
        $settings = $this->getSettings();
        $settings = $this->manifest->settings;
        if (! $settings instanceof Settings) {
            return [];
        }
@@ -175,6 +170,14 @@ abstract class BasePlugin implements PluginInterface
        return $settings->{$type};
    }

    /**
     * @return list<string>
     */
    final public function getHooks(): array
    {
        return $this->manifest->hooks;
    }

    final public function getKey(): string
    {
        return $this->key;
+8 −0
Original line number Diff line number Diff line
@@ -16,7 +16,13 @@ return [
    'authors' => 'Authors',
    'author_email' => 'Email {authorName}',
    'author_homepage' => '{authorName} homepage',
    'declaredHooks' => 'Declared hooks',
    'settings' => 'Settings',
    'settingsTitle' => '{type, select,
        podcast {{pluginName} podcast settings}
        episode {{pluginName} episode settings}
        other {{pluginName} general settings}
    }',
    'view' => 'View',
    'activate' => 'Activate',
    'deactivate' => 'Deactivate',
@@ -29,6 +35,8 @@ return [
        'analytics' => 'Analytics',
        'accessibility' => 'Accessibility',
    ],
    'noDescription' => 'No description',
    'noReadme' => 'No README file found.',
    'messages' => [
        'saveSettingsSuccess' => '{pluginName} settings were successfully saved!',
    ],
+2 −2
Original line number Diff line number Diff line
@@ -46,8 +46,8 @@ class Person extends ManifestObject

            $data = [
                'name'  => $matches['name'],
                'email' => $matches['email'],
                'url'   => $matches['url'],
                'email' => $matches['email'] ?? null,
                'url'   => $matches['url'] ?? null,
            ];
        }

+2 −2
Original line number Diff line number Diff line
@@ -41,10 +41,10 @@ $isEpisodeArea = isset($podcast) && isset($episode);
                        <div class="inline-flex items-center">
                            <?php // @icon('exchange-dollar-fill')?>
                            <x-IconButton uri="<?= route_to('subscription-list', $podcast->id) ?>" glyph="exchange-dollar-fill" variant="secondary" size="large" class="p-0 mr-2 border-0"><?= ($isEpisodeArea && $episode->is_premium) ? lang('PremiumPodcasts.episode_is_premium') : lang('PremiumPodcasts.podcast_is_premium') ?></x-IconButton>
                            <x-Heading tagName="h1" size="large" class="truncate"><?= $this->renderSection('pageTitle') ?></x-Heading>
                            <x-Heading tagName="h1" size="large" class="max-w-sm truncate"><?= $this->renderSection('pageTitle') ?></x-Heading>
                        </div>
                    <?php else: ?>
                            <x-Heading tagName="h1" size="large" class="truncate"><?= $this->renderSection('pageTitle') ?></x-Heading>
                            <x-Heading tagName="h1" size="large" class="max-w-lg truncate"><?= $this->renderSection('pageTitle') ?></x-Heading>
                    <?php endif; ?>
                        <?= $this->renderSection('headerLeft') ?>
                    </div>
Loading