octoberfa/oc-persian

How to disable flipcss for the backend only

Closed this issue · 2 comments

Hello,
It'll be nice to have the option to disable the flipcss just for the backend.
Most users prefer to user the backend in english while the frontend is localised.
THanks

flipcss is a twig filter if you don't want back-end in rtl mode simply disable or uninstall plugin.
you can write a simple plugin for flipcss twig filter with using this class https://github.com/octoberfa/oc-persian/blob/master/classes/CssFlipper.php and add this code in your plugin.php file

class Plugin extends PluginBase
{
    public function register()
    {
        $this->registerMarkupTags();
    }
    public function registerMarkupTags()
    {
        MarkupManager::instance()->registerCallback(function ($manager) {
            $manager->registerFilters([
                'flipCss' => [$this, 'flipCss'],
            ]);
        });
    }

    /**
     * Twig Markup Filter 'flipCss'
     * @param $paths
     * @param bool $force
     * @return array|string
     */
    public function flipCss($paths)
    {
        if (!is_array($paths)) {
            $paths = [$paths];
        }
        $rPaths = [];
        foreach ($paths as $path) {
            $assetPath = $path;
            if (File::exists(dirname($assetPath) . '/' . File::name($assetPath) . '.rtl.' . File::extension($assetPath))) {
                $newPath = dirname($assetPath) . '.rtl.' . File::extension($assetPath);
            } else {
                $newPath = CssFlipper::flipCss($assetPath, true);
            }
            $rPaths[] = $newPath;
        }
        return $rPaths;
    }
}