Code Monkey home page Code Monkey logo

Comments (5)

tractorcow avatar tractorcow commented on August 20, 2024

Hi @Josua2012 ,

The main reasons for having this function, are:

  • Separate persistant storage for current locale, meaning that you can view the site and edit it without the locale being inherited across the two browser windows
  • Prevent filtered objects from being filtered in the CMS

I will admit ignorance to the specifics of your module, but I can add a hook into this function for you to override it as necessary in your controller. Will update you shortly.

from silverstripe-fluent.

tractorcow avatar tractorcow commented on August 20, 2024

I've allowed you to work around this with tractorcow@7dbf340.

Now you can implement isFrontend in your controller to manually specify if this is a frontend controller or not. You can also add this as an extension to your controller, if you don't want to hard code it into your module.

Test cases and documentation added.

    public static function is_frontend($ignoreController = false) {

        // No controller - Possibly pre-route phase, so check URL
        if($ignoreController || !Controller::has_curr()) {
            // $_SERVER['REQUEST_URI'] indeterminatelys lead with '/', so trim here
            $base = preg_quote(ltrim(Director::baseURL(), '/'), '/');
            return !preg_match('/^(\/)?'.$base.'admin(\/|$)/i', $_SERVER['REQUEST_URI']);
        }

        // Check if controller is aware of its own role
        $controller = Controller::curr();
        if($controller->hasMethod('isFrontend')) return $controller->isFrontend();

        // Default to return false for any CMS controller
        return !($controller instanceof AdminRootController)
            && !($controller instanceof LeftAndMain);
    }

from silverstripe-fluent.

tractorcow avatar tractorcow commented on August 20, 2024

Also, don't forget to follow the instructions under https://github.com/tractorcow/silverstripe-fluent#using-custom-controllers

If you are using a custom controller you need to add the FluentContentController extension.

from silverstripe-fluent.

tractorcow avatar tractorcow commented on August 20, 2024

Don't worry if that missing-controller line is met... there is a bit of pre-request handing detection that's done in order to best-guess the user locale, just in case the handling controller doesn't correctly install the locale (as Security controller does, due to it not calling onBeforeInit on its nested Page_Controller).

If you add the FluentContentController extension, your custom controller will correctly set the locale from the admin-view session field.

from silverstripe-fluent.

Josua2012 avatar Josua2012 commented on August 20, 2024

I had to make an extension with isFrontend function for that controller (CreateEcommerceVariations).
Now the detection works correctly.

Thanks Damian

from silverstripe-fluent.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.