Unverified Commit 8c64f25a authored by Yassine Doghri's avatar Yassine Doghri
Browse files

fix(category): remove uncategorized option to enforce users in choosing a category

Apple podcasts requires a category to submit a valid podcast RSS feed. The "uncategorized" category
is not a valid category.
parent 433745f1
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ class AddCategories extends Migration
            'parent_id' => [
                'type' => 'INT',
                'unsigned' => true,
                'null' => true,
            ],
            'code' => [
                'type' => 'VARCHAR',
+110 −117

File changed.

Preview size limit exceeded, changes collapsed.

+84 −0
Original line number Diff line number Diff line
@@ -172,3 +172,87 @@ if (! function_exists('form_multiselect')) {
}

//--------------------------------------------------------------------

if (! function_exists('form_dropdown')) {
    /**
     * Drop-down Menu (based on html select tag)
     *
     * @param array<string, mixed>|string $data
     * @param array<string, string> $options
     * @param string|string[] $selected
     * @param array<string, mixed>|string $extra
     */
    function form_dropdown(
        string | array $data = '',
        array $options = [],
        string | array $selected = [],
        string | array $extra = ''
    ): string {
        $defaults = [];
        if (is_array($data)) {
            if (isset($data['selected'])) {
                $selected = $data['selected'];
                unset($data['selected']); // select tags don't have a selected attribute
            }
            if (isset($data['options'])) {
                $options = $data['options'];
                unset($data['options']); // select tags don't use an options attribute
            }
        } else {
            $defaults = [
                'name' => $data,
            ];
        }

        if (! is_array($selected)) {
            $selected = [$selected];
        }
        if (! is_array($options)) {
            $options = [$options];
        }

        // standardize selected as strings, like  the option keys will be.
        foreach ($selected as $key => $item) {
            $selected[$key] = (string) $item;
        }

        $placeholderOption = '';
        if (isset($extra['placeholder'])) {
            $placeholderOption = '<option value="" disabled="disabled" hidden="hidden"' . (in_array(
                '',
                $selected,
                true
            ) ? ' selected="selected"' : '') . '>' . $extra['placeholder'] . '</option>';
            unset($extra['placeholder']);
        }

        $extra = stringify_attributes($extra);
        $multiple = (count($selected) > 1 && stripos($extra, 'multiple') === false) ? ' multiple="multiple"' : '';
        $form = '<select ' . rtrim(parse_form_attributes($data, $defaults)) . $extra . $multiple . ">\n";
        $form .= $placeholderOption;

        foreach ($options as $key => $val) {
            $key = (string) $key;
            if (is_array($val)) {
                if ($val === []) {
                    continue;
                }
                $form .= '<optgroup label="' . $key . "\">\n";
                foreach ($val as $optgroupKey => $optgroupVal) {
                    $sel = in_array($optgroupKey, $selected, true) ? ' selected="selected"' : '';
                    $form .= '<option value="' . htmlspecialchars($optgroupKey) . '"' . $sel . '>'
                            . $optgroupVal . "</option>\n";
                }
                $form .= "</optgroup>\n";
            } else {
                $form .= '<option value="' . htmlspecialchars($key) . '"'
                        . (in_array($key, $selected, true) ? ' selected="selected"' : '') . '>'
                        . $val . "</option>\n";
            }
        }

        return $form . "</select>\n";
    }
}

// ------------------------------------------------------------------------
+1 −0
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ return [
            'These fields will impact your audience and competition.',
        'language' => 'Language',
        'category' => 'Category',
        'category_placeholder' => 'Select a category…',
        'other_categories' => 'Other categories',
        'parental_advisory' => [
            'label' => 'Parental advisory',
+1 −0
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ return [
            'Ces champs auront un impact sur votre audience et votre concurrence.',
        'language' => 'Langue',
        'category' => 'Catégorie',
        'category_placeholder' => 'Sélectionner une catégorie…',
        'other_categories' => 'Autres catégories',
        'parental_advisory' => [
            'label' => 'Avertissement parental',
Loading