Skip to content

Commit

Permalink
Merge pull request #6 from thewebmen/feature/improve-readme-and-some-…
Browse files Browse the repository at this point in the history
…overal-improvements

Updated README and added docs and contributing guides. Removed image from MenuItem
  • Loading branch information
Dennis Prins committed Jan 20, 2022
2 parents 7cd9504 + ae65af1 commit c413217
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 26 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Changelog

The changelog is found on [https://github.com/thewebmen/silverstripe-menustructure/releases](https://github.com/thewebmen/silverstripe-menustructure/releases)
19 changes: 19 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Contributing

## Bugtracker
Bugs are tracked in the issues section of this repository. Before submitting an issue please read over
existing issues to ensure yours is unique.

If the issue does look like a new bug:

- Create a new issue
- Describe the steps required to reproduce your issue, and the expected outcome. Unit tests, screenshots
and screencasts can help here.
- Describe your environment as detailed as possible: SilverStripe version, Browser, PHP version,
Operating System, any installed SilverStripe modules.

## Security
Please report security issues to the module maintainers directly. Please don't file security issues in the bugtracker.

## Copyright
By supplying code to this module in any form you agree to assign copyright of that code to Webmen, on the condition that Webmen releases that code under a form of open source license.
45 changes: 23 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
# SilverStripe Menustructure module

## Protect menus from deletion
```yaml
TheWebmen\Menustructure\Model\Menu:
protected_menus:
- 'main-menu'
- 'footer-col1'
- 'footer-col2'
- 'footer-col3'
```

## Usage
Render a menu in any template using:
```
$MenustructureMenu('menu-slug')
```
Render a menu using a custom template using:
```
$MenustructureMenu('menu-slug', 'Menus/MainMenu')
```

## Todo
* Improve docs
This module makes it possible to use multiple menus on 1 SilverStripe site, instead of using the "default" menu.
The menus in this module are also more customizable then the "default" silverstripe menu.

# Requirements
* SilverStripe 4.x

# Installation
`composer require thewebmen/silverstripe-menustructure`

# Documentation
* [Configuration](docs/en/configuration.md)

# License
See [License](LICENSE)

## Maintainers
* [Webmen](https://www.webmen.nl/) <developement@webmen.nl>

## Contributing
See [Contributing](CONTRIBUTING.md)

## Development and contribution
If you would like to make contributions to the module please ensure you raise a pull request and discuss with the module maintainers.
35 changes: 35 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Silverstripe Menustructure configuration
## Usage
Render a menu in any template using:
```
$MenustructureMenu('menu-slug')
```

## Protect menus from deletion
You can add some custom configuration file (eg. `app/_config/menu.yml)` to your project to protect menus.\
See the example below;

```yaml
TheWebmen\Menustructure\Model\Menu:
protected_menus:
- 'main-menu'
- 'footer-col1'
- 'footer-col2'
- 'footer-col3'
```

## Customizing
### Templates
It is possible to render the menus in custom templates.
De default template is found in this module under `templates/TheWebmen/Menustructure/Model/Menu.ss`.

You can use this code as example for custom menus.

### Render the custom menu

Render a menu using a custom template using:
```
$MenustructureMenu('menu-slug', 'Menus/MainMenu')
```

Here the first argument is the slug of the menu and the second argument is the template you want to use.
4 changes: 0 additions & 4 deletions src/Model/MenuItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace TheWebmen\Menustructure\Model;

use SilverStripe\Assets\File;
use SilverStripe\Assets\Image;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Control\Controller;
use SilverStripe\Forms\DropdownField;
Expand Down Expand Up @@ -36,7 +35,6 @@ class MenuItem extends DataObject {
];

private static $has_one = [
'Image' => Image::class,
'File' => File::class,
'Menu' => Menu::class,
'ParentItem' => MenuItem::class,
Expand All @@ -48,7 +46,6 @@ class MenuItem extends DataObject {
];

private static $owns = [
'Image',
'File'
];

Expand Down Expand Up @@ -88,7 +85,6 @@ public function getCMSFields()
}

$fields->addFieldToTab('Root.Main', $fields->dataFieldByName('OpenInNewWindow'));
$fields->addFieldToTab('Root.Main', $fields->dataFieldByName('Image')->setFolderName('Menus')->setDescription('Optional image, can be used in some templates.'));

$fields->removeByName('Items');
if($this->exists()){
Expand Down

0 comments on commit c413217

Please sign in to comment.