Skip to content

Commit c249a9b

Browse files
committed
Initial commit
0 parents  commit c249a9b

22 files changed

+1086
-0
lines changed

.editorconfig

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# For more information about the properties used in this file,
2+
# please see the EditorConfig documentation:
3+
# http://editorconfig.org
4+
5+
[*]
6+
charset = utf-8
7+
end_of_line = lf
8+
indent_size = 4
9+
indent_style = space
10+
insert_final_newline = true
11+
trim_trailing_whitespace = true
12+
13+
[{*.yml,*.json}]
14+
indent_size = 2
15+
16+
[{*.ss}]
17+
indent_style = tab

.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

.gitignore

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Thumbs.db
2+
web.config
3+
.log
4+
.buildpath
5+
.project
6+
.settings
7+
.idea
8+
.DS_Store
9+
._.DS_Store
10+
.codekit
11+
.sublime-*
12+
.sass-cache
13+
prepros.cfg
14+
node_modules

.scrutinizer.yml

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
inherit: true
2+
3+
checks:
4+
php:
5+
verify_property_names: true
6+
verify_argument_usable_as_reference: true
7+
verify_access_scope_valid: true
8+
useless_calls: true
9+
use_statement_alias_conflict: true
10+
variable_existence: true
11+
unused_variables: true
12+
unused_properties: true
13+
unused_parameters: true
14+
unused_methods: true
15+
unreachable_code: true
16+
too_many_arguments: true
17+
sql_injection_vulnerabilities: true
18+
simplify_boolean_return: true
19+
side_effects_or_types: true
20+
security_vulnerabilities: true
21+
return_doc_comments: true
22+
return_doc_comment_if_not_inferrable: true
23+
require_scope_for_properties: true
24+
require_scope_for_methods: true
25+
require_php_tag_first: true
26+
psr2_switch_declaration: true
27+
psr2_class_declaration: true
28+
property_assignments: true
29+
prefer_while_loop_over_for_loop: true
30+
precedence_mistakes: true
31+
precedence_in_conditions: true
32+
phpunit_assertions: true
33+
php5_style_constructor: true
34+
parse_doc_comments: true
35+
parameter_non_unique: true
36+
parameter_doc_comments: true
37+
param_doc_comment_if_not_inferrable: true
38+
optional_parameters_at_the_end: true
39+
one_class_per_file: true
40+
no_unnecessary_if: true
41+
no_trailing_whitespace: true
42+
no_property_on_interface: true
43+
no_non_implemented_abstract_methods: true
44+
no_error_suppression: true
45+
no_duplicate_arguments: true
46+
no_commented_out_code: true
47+
newline_at_end_of_file: true
48+
missing_arguments: true
49+
method_calls_on_non_object: true
50+
instanceof_class_exists: true
51+
foreach_traversable: true
52+
fix_line_ending: true
53+
fix_doc_comments: true
54+
duplication: true
55+
deprecated_code_usage: true
56+
deadlock_detection_in_loops: true
57+
code_rating: true
58+
closure_use_not_conflicting: true
59+
catch_class_exists: true
60+
blank_line_after_namespace_declaration: false
61+
avoid_multiple_statements_on_same_line: true
62+
avoid_duplicate_types: true
63+
avoid_conflicting_incrementers: true
64+
avoid_closing_tag: true
65+
assignment_of_null_return: true
66+
argument_type_checks: true
67+
68+
filter:
69+
paths: [src/*, tests/*]

LICENSE.md

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
BSD 3-Clause License
2+
3+
Copyright (c) 2017, gorriecoe
4+
All rights reserved.
5+
6+
Redistribution and use in source and binary forms, with or without
7+
modification, are permitted provided that the following conditions are met:
8+
9+
* Redistributions of source code must retain the above copyright notice, this
10+
list of conditions and the following disclaimer.
11+
12+
* Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
15+
16+
* Neither the name of the copyright holder nor the names of its
17+
contributors may be used to endorse or promote products derived from
18+
this software without specific prior written permission.
19+
20+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Silverstripe menus
2+
3+
4+
## Installation
5+
Composer is the recommended way of installing SilverStripe modules.
6+
```
7+
composer require gorriecoe/silverstripe-menu
8+
```
9+
10+
## Requirements
11+
12+
- silverstripe/framework ^4.0
13+
- symbiote/silverstripe-gridfieldextensions ^3.1
14+
- gorriecoe/silverstripe-links
15+
16+
## Maintainers
17+
18+
- [Gorrie Coe](https://github.com/gorriecoe)
19+
20+
## Creating custom menus
21+
22+
As it is common to reference MenuSets by name in templates, you can configure sets to be created automatically during the /dev/build task. These sets cannot be deleted through the CMS.
23+
24+
```
25+
gorriecoe\Menu\Models\MenuSet:
26+
sets:
27+
main: Main menu
28+
footer:
29+
title: Footer menu
30+
nested: false
31+
```
32+
33+
## Adding links to menus
34+
35+
Once you have created your menus you can add links.
36+
37+
## Usage in template
38+
39+
```
40+
<ul>
41+
<% loop MenuSet('footer') %>
42+
<li>
43+
{$Me}
44+
</li>
45+
<% end_loop %>
46+
</ul>
47+
```

_config/config.yml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
Name: menuconfig
3+
Only:
4+
moduleexists: silverstripe/subsite
5+
---
6+
gorriecoe\Menu\Models\MenuSet:
7+
extensions:
8+
- gorriecoe\Menu\Extensions\MenuSetSubsiteExtension
9+
---
10+
Only:
11+
moduleexists: 'silverstripe/graphql'
12+
---
13+
SilverStripe\GraphQL\Controller:
14+
schema:
15+
types:
16+
menuset: gorriecoe\Menu\GraphQL\MenuSetTypeCreator
17+
menulink: gorriecoe\Menu\GraphQL\MenuLinkTypeCreator
18+
queries:
19+
menuset: gorriecoe\Menu\GraphQL\MenuSetQueryCreator
20+
menusets: gorriecoe\Menu\GraphQL\MenuSetsQueryCreator
21+
menulink: gorriecoe\Menu\GraphQL\MenuLinkQueryCreator
22+
menulinks: gorriecoe\Menu\GraphQL\MenuLinksQueryCreator

client/img/menu.svg

+1
Loading

composer.json

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "gorriecoe/silverstripe-menu",
3+
"description": "Creates multiple menus.",
4+
"type": "silverstripe-vendormodule",
5+
"license": "BSD 3-Clause",
6+
"authors": [
7+
{
8+
"name": "Gorrie Coe",
9+
"email": "[email protected]"
10+
}
11+
],
12+
"keywords": [
13+
"silverstripe",
14+
"modular",
15+
"cms",
16+
"menu",
17+
"link"
18+
],
19+
"homepage": "http://github.com/gorriecoe/silverstripe-menu",
20+
"require": {
21+
"silverstripe/admin": "^1.0",
22+
"symbiote/silverstripe-gridfieldextensions": "^3.1",
23+
"gorriecoe/silverstripe-links": "dev-master"
24+
},
25+
"extra": {
26+
"installer-name": "menu",
27+
"expose": [
28+
"client"
29+
]
30+
}
31+
}

contributing.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Contributing
2+
- Maintenance on this module is a shared effort of those who use it
3+
- To contribute improvements to the code, ensure you raise a pull request and discuss with the module maintainers
4+
- Please follow the SilverStripe [code contribution guidelines](https://docs.silverstripe.org/en/contributing/code/) and [Module Standard](https://docs.silverstripe.org/en/developer_guides/extending/modules/#module-standard)
5+
- Supply documentation that followS the [GitHub Flavored Markdown](https://help.github.com/articles/markdown-basics/) conventions
6+
- When having discussions about this module in issues or pull request please adhere to the [SilverStripe Community Code of Conduct](https://docs.silverstripe.org/en/contributing/code_of_conduct/)
7+
## Contributor license agreement
8+
By supplying code to this module in patches, tickets and pull requests, you agree to assign copyright
9+
of that code to gorriecoe, on the condition that these code changes are released under the
10+
same BSD license as the original module. We ask for this so that the ownership in the license is clear
11+
and unambiguous. By releasing this code under a permissive license such as BSD, this copyright assignment
12+
won't prevent you from using the code in any way you see fit.

src/admin/MenuSetAdmin.php

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
3+
namespace gorriecoe\Menu\Admin;
4+
5+
use gorriecoe\Menu\Models\MenuSet;
6+
use SilverStripe\Admin\ModelAdmin;
7+
use SilverStripe\Forms\GridField\GridFieldPrintButton;
8+
use SilverStripe\Forms\GridField\GridFieldImportButton;
9+
use SilverStripe\Forms\GridField\GridFieldExportButton;
10+
11+
/**
12+
* CMS Admin area to maintain menus
13+
*
14+
* @package silverstripe
15+
* @subpackage silverstripe-menu
16+
*/
17+
class MenuSetAdmin extends ModelAdmin
18+
{
19+
/**
20+
* Managed data objects for CMS
21+
* @var array
22+
*/
23+
private static $managed_models = [
24+
MenuSet::class
25+
];
26+
27+
/**
28+
* URL Path for CMS
29+
* @var string
30+
*/
31+
private static $url_segment = 'menus';
32+
33+
/**
34+
* Menu title for Left and Main CMS
35+
* @var string
36+
*/
37+
private static $menu_title = 'Menus';
38+
39+
/**
40+
* @var string
41+
*/
42+
private static $menu_icon = 'gorriecoe/silverstripe-menu: client/img/menu.svg';
43+
44+
/**
45+
* @var int
46+
*/
47+
private static $menu_priority = 9;
48+
49+
/**
50+
* @param Int $id
51+
* @param FieldList $fields
52+
* @return Form
53+
*/
54+
public function getEditForm($id = null, $fields = null)
55+
{
56+
$form = parent::getEditForm($id, $fields);
57+
$form->Fields()
58+
->fieldByName($this->sanitiseClassName($this->modelClass))
59+
->getConfig()
60+
->removeComponentsByType([
61+
GridFieldImportButton::class,
62+
GridFieldExportButton::class,
63+
GridFieldPrintButton::class
64+
]);
65+
return $form;
66+
}
67+
}
+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
namespace gorriecoe\Menu\Extensions;
4+
5+
use SilverStripe\Subsites\Model\Subsite;
6+
use SilverStripe\Forms\FieldList;
7+
use SilverStripe\Forms\HiddenField;
8+
use SilverStripe\ORM\DataExtension;
9+
10+
/**
11+
* Adds subsite support if installed
12+
*
13+
* @package silverstripe
14+
* @subpackage silverstripe-menu
15+
*/
16+
class MenuSetSubsiteExtension extends DataExtension
17+
{
18+
/**
19+
* Has_one relationship
20+
* @var array
21+
*/
22+
private static $has_one = array(
23+
'Subsite' => Subsite::class
24+
);
25+
26+
/**
27+
* Update Fields
28+
* @return FieldList
29+
*/
30+
public function updateCMSFields(FieldList $fields)
31+
{
32+
$owner = $this->owner;
33+
$fields->addFieldToTab(
34+
"Root.Main",
35+
HiddenField::create(
36+
'SubsiteID',
37+
'SubsiteID',
38+
Subsite::currentSubsiteID()
39+
)
40+
);
41+
return $fields;
42+
}
43+
44+
/**
45+
* Event handler called before writing to the database.
46+
*/
47+
public function onBeforeWrite()
48+
{
49+
$owner = $this->owner;
50+
if(!$owner->ID && !$owner->SubsiteID){
51+
$owner->SubsiteID = Subsite::currentSubsiteID();
52+
}
53+
parent::onBeforeWrite();
54+
}
55+
}

0 commit comments

Comments
 (0)