Code Monkey home page Code Monkey logo

silverstripe-betternavigator's Introduction

BetterNavigator for Silverstripe

Diagram of module

This module is intended to replicate and expand upon the functionality provided by Silverstripe's built-in SilverStripeNavigator class. It provides a handy front-end menu for CMS users which offers these features:

For Content Authors

  • Indicates to a user that they are logged in
  • Indicates whether they are viewing draft or live content
  • Quickly edit the page you're viewing

For Developers

  • When in Dev Mode links are included for accessing most of Silverstripe's URL Variable Tools
  • Developers can access these tools on a live website by nominating themselves as a developer in the site config

Requirements

Silverstripe 5.0 (4.0+ and 3.1+ through previous releases)

Installation

Add "jonom/silverstripe-betternavigator" to your composer requirements.

composer require jonom/silverstripe-betternavigator

Upgrading

  • 6.0: the namespace for this module's templates and configuration was changed in v6 to include a JonoM prefix. You may need to update your template directory structure and/or app configuration accordingly.

How to use

The navigator is auto-injected into your template, and no code changes are needed.

If your website uses caching, make sure BetterNavigator's output is excluded.

Access developer tools on a live website

You can mark certain CMS users as developers in your site's config, so they can access developer tools when logged in. Example YAML:

JonoM\BetterNavigator:
  developers:
    - '[email protected]'
    - '[email protected]'

Customisation

Navigator display

You can control whether the navigator is displayed by defining a showBetterNavigator(): bool method in any controller with the extension applied. By default the navigator will only show on controllers that have a dataRecord property that is an instance of SilverStripe\CMS\Model\SiteTree.

public function showBetterNavigator()
{
    // A user-defined setting
    return $this->ShowDebugTools;
}

Layout options

BetterNavigator can be made translucent when collapsed by adding the following config setting:

JonoM\BetterNavigator:
  translucent: true

BetterNavigator's default position is 'right-top', but can be changed to 'right-bottom', 'left-top' or 'left-bottom'. Example:

JonoM\BetterNavigator:
  position: 'right-bottom'

Template additions/overrides

BetterNavigator's output is controlled by templates so it can be easily overridden.

Some empty <% include %> placeholders are included to let you easily add more content (new buttons for instance). Just create any of these templates in your theme or app directory and add your content:

  • templates/JonoM/BetterNavigator/Includes/ BetterNavigatorExtraContent.ss
  • templates/JonoM/BetterNavigator/Includes/ BetterNavigatorExtraDebugging.ss
  • templates/JonoM/BetterNavigator/Includes/ BetterNavigatorExtraDevTools.ss

The BetterNavigator.ss template's scope is set to the page that is being viewed, so any methods available in your page controller will be available in the BetterNavigator.ss template. This should allow you to add custom links by page type and introduce complex logic if you want to.

Overriding the "Edit in CMS" Link

There may be occasions when you wish to override the "Edit in CMS" link. For example to point to the edit form for a displayed DataObject, rather than for the Page itself. To do so, simply add a BetterNavigatorEditLink() method to your page's Controller, e.g.:

// EventsPageController.php

/**
 * Return an alternative URL for the BetterNavigator Edit in CMS link.
 * @return string
 */
public function BetterNavigatorEditLink()
{
    $event = $this->displayedEvent();
    return $event->canEdit() ? CMSEditLinkAPI::find_edit_link_for_object($event) : false;
}

(This example uses sunnysideup/cms_edit_link_field to automatically find an edit link for a specified DataObject, but you can return any URL.)

Overriding the permissions required for the cms edit link

By default users are required to have at least the CMS_ACCESS_CMSMain permission in order to see the edit link in better navigator, you can override this by setting the better_navigator_edit_permission configuration option on your controller to another permission code or an array of permission codes, e.g.:

My\Namespace\EventController:
  better_navigator_edit_permission: "CUSTOM_PERMISSION_CODE"
  better_navigator_edit_permission_mode: "any" #Optional, but can be either "any" or "all" (defaults to "all")

Recommended companions

DebugBar for better debugging tools

This module provide quick access to Silverstripe's built in URL Variable Tools but reading their output isn't much fun. You can peek under Silverstripe's hood much more conveniently using lekoala's Silverstripe DebugBar

Environment Awareness to save your sites from yourself

Environment Awareness makes it obvious which environment you're in, to make it less likely that you nuke something in prod. You can display the current environment right in the navigator.

Maintainer contact

Jono Menz

Sponsorship

If you want to boost morale of the maintainer you're welcome to make a small monthly donation through GitHub, or a one time donation through PayPal. ❤️ Thank you!

Please also feel free to get in touch if you want to hire the maintainer to develop a new feature, or discuss another opportunity.

silverstripe-betternavigator's People

Contributors

3dgoo avatar andreaslang50 avatar andrewandante avatar anselmdk avatar bob-plastyk avatar chrispenny avatar edwilde avatar howardgrigg avatar jedateach avatar jonom avatar korthjp17 avatar mellm0 avatar michalkleiner avatar purplespider avatar sb-relaxt-at avatar thebnl avatar undefinedoffset avatar wernerkrauss avatar xini avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

silverstripe-betternavigator's Issues

Make CMS Link work for Data Objects

Is there an easy way to make the "Edit in CMS" link work for a page displaying a DataObject? e.g. to take you to editing that DataObject in the existing ModelAdmin/GridField? (Currently, it just takes you to editing the page).

Newest release breaks links for sites in subfolder

In 2.1 if I had a site in e.g. locahost/foo, if I click on any of the links this is run on the subfolder. However on 3.0 it removes this, so instead of e.g. localhost/foo/dev/build it gets localhost/dev/build.

Empty templates $val .= '';

BetterNavigatorExtraContent.ss and BetterNavigatorExtraDevTools.ss are empty, so they render $val .= ''; on the page.

I realise this is really a bug in framework, but its kind of annoying when you just want to install the module.

Add locale parameter (e.g. ?l=de_DE) to "Edit in CMS" button for working better with the fluent module

Hi @jonom
thanks for the great work. While implementing your module for a client the question arised if it would be possible to directly send the user to the CMS with the correct locale set when working in conjunction with the fluent module. It would need to append the locale to the url as an l parameter. I know it's currently using the $EditLink call in the template, but I am unsure if it makes sense to overload that method (could it have other implications?) or do a conditional in the template directly. Perhaps you have more insights or thoughts on this. Thanks.

Position and translucent config feature

Hi Jono,

I have created a fork and a branch of this module for myself with some minor features. I thought I would share the changes with you in case you were interested in merging in any of these.

This is the branch:
https://github.com/3Dgoo/silverstripe-betternavigator/tree/feature/navigator-location-config

When I use the better navigator I usually drop it down to the bottom right of the site so it doesn't clash with the site navigation. I also make it semi-transparent when not active.

I've created this branch that allows us to set the position (left-top, right-top, right-bottom or left-bottom) through the config. If the config value is not set it defaults to right-top.

In the branch, we can also toggle the semi-transparent styling on and off through the config too.

Let me know if you're keen on using any of this. If not, all cool. Feel free to close this issue either way.

Thanks.

[Question] How does one add extra dev tool links in 5.4.1

I noticed that in the latest release (v6) that the template paths/namespaces were updated. But I am still using Silverstripe 4 and so I'm stuck with version 5.4.1 and cannot seem to figure out how to add extra links to the developer tools section

I have tried templates/JonoM/BetterNavigator/Includes/BetterNavigatorExtraDevTools.ss, templates/BetterNavigator/Includes/ BetterNavigatorExtraDevTools.ss and templates/BetterNavigator/BetterNavigator/Includes/ BetterNavigatorExtraDevTools.ss without any effect (and I made sure to flush after updating the template).

Am I using the wrong paths? Or does this have something to do with me trying to overwrite the template from my own module rather then the theme template folder?

Conflicting template variables

I was recently working on a project that would break with better navigator because I had a member controller action. This is also a variable that the better navigator looks for in the global template variable space.

Can I suggest that the data rendered here be wrapped inside another ArrayData variable like BetterNavigatorData? The template will need to be adjusted accordingly.

This will ensure that BetterNavigator doesn't pick up controller/model functions/fields that users have defined.

I can't imagine this will break backwards compatibility because the BetterNavigator template is the one looking for these variables.

Includes JS even if not rendered

afterCallActionHandler's check of DBHTMLText means there are multiple reasons BetterNavigator might not be rendered, and the js still included.

Navigator doesn't render on SS 4.1.0

The BetterNavigatorExtension->isAPage() function introduced in #27 doesn't return return true when $this->owner is a subclass of SiteTree.

Changing the function like so seems to work

 protected function isAPage() {
     return $this->owner
-        && $this->owner->dataRecord
-        && $this->owner->dataRecord instanceof SiteTree
-        && $this->owner->dataRecord->ID > 0;
+        && $this->owner instanceof SiteTree
+        && $this->owner->ID > 0;
 }

However, this causes another error

Emergency] Uncaught TypeError: Argument 1 passed to SilverStripe\CMS\Controllers\SilverStripeNavigator::__construct() must implement interface SilverStripe\ORM\CMSPreviewable, null given

Not sure what has changed between SS3 and SS4 with the functionality of extensions, but

protected function isAPage() {
    echo get_class($this->owner->dataRecord);
    exit;
    //...
}

prints JonoM\BetterNavigator\Extension\BetterNavigatorExtension

Odd little line next to view draft

image
Left-top of the eye has an... interesting little line, which has confused me quite a few times, thinking my screen was dirty/having broken pixels

Template customisation namespace is wrong

Docs advise using e.g. templates/JonoM/BetterNavigator/Includes/ BetterNavigatorExtraContent.ss but code calls ->renderWith('BetterNavigator\\BetterNavigator'), so in fact if the templates are in a JonoM directory they get ignored.

Error on page controllers that don't have a model

Some controllers don't have an associated model, such as when registering for an event using the eventregistration module. It constructs a controller with no associated page.
The navigator breaks in these cases.

Mind you, this appears to be an issue with the default SilverStripeNavigator.

Fatal error: Wrong parameters for Exception([string $exception [, long $code [, Exception $previous = NULL]]]) in /...../cms/code/controllers/SilverStripeNavigator.php on line 28
Call Stack
#   Time    Memory  Function    Location
1   0.0006  283848  {main}( )   ../main.php:0
2   0.0521  9456776 Director::direct( ) ../main.php:176
3   0.0569  10344664    Director::handleRequest( )  ../Director.php:153
4   0.0594  10546192    ModelAsController->handleRequest( ) ../Director.php:367
5   0.1307  16381000    ContentController->handleRequest( ) ../ModelAsController.php:78
6   0.1389  17450936    ContentController->handleRequest( ) ../ContentController.php:179
7   0.1463  18214624    ContentController->handleRequest( ) ../ContentController.php:179
8   0.1468  18220160    Controller->handleRequest( )    ../ContentController.php:198
9   0.1666  18515784    RequestHandler->handleRequest( )    ../Controller.php:153
10  0.1810  19350520    ContentController->handleRequest( ) ../RequestHandler.php:222
11  0.1832  19358920    Controller->handleRequest( )    ../ContentController.php:198
12  0.1885  19362800    RequestHandler->handleRequest( )    ../Controller.php:153
13  0.1900  19500856    ContentController->handleRequest( ) ../RequestHandler.php:222
14  0.1922  19507400    Controller->handleRequest( )    ../ContentController.php:198
15  0.2557  24304960    RequestHandler->handleRequest( )    ../Controller.php:153
16  0.2561  24307456    Controller->handleAction( ) ../RequestHandler.php:200
17  0.2561  24308800    RequestHandler->handleAction( ) ../Controller.php:194
18  0.2561  24309152    EventRegisterController->index( )   ../RequestHandler.php:288
19  0.3099  26044984    SSViewer->process( )    ../EventRegisterController.php:92
20  0.3734  29543016    SSViewer->includeGeneratedTemplate( )   ../SSViewer.php:1064
....
29  0.5139  29965032    ViewableData->obj( )    ../ViewableData.php:403
30  0.5139  29965080    ContentController->SilverStripeNavigator( ) ../ViewableData.php:363
31  0.5159  30270368    SilverStripeNavigator::get_for_record( )    ../ContentController.php:307
32  0.5159  30270864    SilverStripeNavigator->__construct( )   ../SilverStripeNavigator.php:81
33  0.5159  30326696    __construct ( )

Version numbering?

Any chance we can start seeing some version numbering to be used with composer?

Semantic versioning would help to understand things about the module by just looking at the number. I've been trying to get in the habit with my modules. It pretty much comes down to creating a new tag on nearly each commit - unless you intentionally make a bunch of commits.

Isn't working?

Hi added this and did a build but doesn't appear to be working?

composer require jonom/silverstripe-betternavigator dev-master

PHP7: Methods with the same name as their class will not be constructors

Silverstripe 3.6 just released which supports php7. Running this module with php7 throws this deprecation error:

[Deprecated] Methods with the same name as their class will not be constructors in a future version of PHP; BetterNavigator has a deprecated constructor

Changing the BetterNavigator method to getBetterNavigator fixes this issue and does not break anything in template files.
Want me to do a PR?

Not included on form response rendered with ->renderWith()

I'm likely doing something wrong but I have a form "InfusionInputsForm" that gets filled out, the FormAction function (calculateInfusion) then does a bunch of calculations and then returns return $arrayData->renderWith(['Infusion']);. That template is rendered correctly but the navigator isn't displayed.

I have defined a BetterNavigatorEditLink() in that pages controller that looks at the ID passed into the form and returns a URL to edit that object directly (i.e. not the page). I note that the URL remains the name of the form function localhost/page/InfusionInputsForm after submitting the form.

Just not sure where to go from here with regards to getting the navigator displayed. Thanks.

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.