Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

All other Modules /

Discuss all other Modules here.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Default simplify configuration


Go to End


3 Posts   1407 Views

Avatar
klikhier

Community Member, 150 Posts

15 October 2010 at 6:53am

froog,

Great module you've created! One question though: I have set up all simplify permissions for a group, and would like to reuse this simplify config for other sites as well. is it possible to define a default simplify config in e.g. _config.php?

Avatar
JL

Community Member, 10 Posts

19 October 2010 at 4:36pm

You can create a simple setup module to create the necessary simplify permissions when you are setting up the site.

setup/_config.php:

<?php

Director::addRules(100, array(
        'admin/setup/$Action/$ID' => 'SetupCMS',
));

setup/code/SetupCMS.php:

<?php

class SetupCMS extends Controller {

    static $url_segment = 'simplify';

    static $allowed_actions = array(
        'simplify'
    );

    function simplify() {
        if (!Member::currentUser()->isAdmin()) {
            return Security::permissionFailure($this);
        }

        // GroupID => Code
        $general_permissions = array(
            1 => array(
                "SIMPLIFY_HIDE_HELP",
                "SIMPLIFY_HIDE_VERSION",
                "SIMPLIFY_HIDE_NON_EDIT_PAGES",
                "SIMPLIFY_HIDE_CREATE",
                "SIMPLIFY_HIDE_SEARCH",
                "SIMPLIFY_HIDE_BATCH_ACTIONS",
                "SIMPLIFY_SHOW_CREATE_OPEN",
                "SIMPLIFY_HIDE_TREE_OPTIONS",
                "SIMPLIFY_DRAGGABLE_ON",
                "SIMPLIFY_HIDE_DRAGGABLE",
            ),
        );

        // GroupID => array(HidePage, HideName, HideType)
        $page_permissions = array(
            1 => array(
                array('Page', 'Behaviour', 'Tab'),
                array('Page', 'Access', 'Tab'),
                array('BlogEntry', 'Behaviour', 'Tab'),
                array('BlogEntry', 'Access', 'Tab'),
            ),
        );

        foreach ($general_permissions as $groupID => $codes) {
            foreach ($codes as $code) {
                $perm = DataObject::get_one("Permission", "Code='{$code}' AND GroupID={$groupID}");
                if (!$perm) {
                    Permission::grant($groupID, $code);
                }
            }
        }

        foreach ($page_permissions as $groupID => $permissions) {
            foreach ($permissions as $permission) {
                $perm = SimplifyPermission::checkField($permission[0], $permission[1], $permission[2], $groupID);
                if (!$perm) {
                    $perm = new SimplifyPermission;
                    $perm->HidePage = $permission[0];
                    $perm->HideName = $permission[1];
                    $perm->HideType = $permission[2];
                    $perm->GroupID = $groupID;
                    $perm->write();
                }
            }
        }

        echo "Simplify settings updated. Simplify rocks!";
    }

}

After that, just access the url /admin/setup/simplify

For a list of simplify permission in the $general_permissions array, you can refer to simplify/code/SimplifyPermissionProvider.php
For a list of simplify permission in the $page_permissions array, you will need to refer to the "Field Tree" after you click on the "Load Field Tree" button in the Simplify interface.

Avatar
klikhier

Community Member, 150 Posts

19 October 2010 at 8:43pm

Thanks!!!