flarum / issue-archive

0 stars 0 forks source link

Custom CSS not overridnig extension's CSS #256

Open pepies opened 5 years ago

pepies commented 5 years ago

Bug Report

Current Behavior https://discuss.flarum.org/d/18380-issue-custom-css-not-overridnig-extension-s-css

Steps to Reproduce 1) Add customCSS overrding Extension one. 2) Viola, its not overrding

Expected Behavior It should

Screenshots There is compiled styles file download image

Environment

Possible Solution In ForumServiceProvider.php methor register () change lines from 85 to these:

$assets->css(function (SourceCollector $sources) {
                $sources->addStringToEnd(function () {
                    return $this->app->make(SettingsRepositoryInterface::class)->get('custom_less');
                });
                $sources->addFile(__DIR__.'/../../less/forum.less');
            });

2) Change content Sourcecollector.php class from Frontend dir to:

/**
     * @var SourceInterface[]
     */
    protected $sources = [];

    /**
     * @var SourceInterface[]
     */
    protected $last = [];

    /**
     * @param string $file
     * @return $this
     */
    public function addFile(string $file)
    {
        $this->sources[] = new FileSource($file);

        return $this;
    }

    /**
     * @param callable $callback
     * @return $this
     */
    public function addString(callable $callback)
    {
        $this->sources[] = new StringSource($callback);

        return $this;
    }

    /**
     * @param callable $callback
     * @return $this
     */
    public function addStringToEnd(callable $callback)
    {
        $this->last[] = new StringSource($callback);

        return $this;
    }

    /**
     * @return SourceInterface[]
     */
    public function getSources()
    {
        return array_merge($this->sources, $this->last);
    }
dsevillamartin commented 5 years ago

You can override those styles if you use !important, however I see how the custom css not being on top could be considered a bug.

pepies commented 5 years ago

You can override those styles if you use !important, however I see how the custom css not being on top could be considered a bug.

Hello, thank for your answer. !important is working but not valid solution. Please see flarum community link in post or directly here: https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity