Skip to content

Commit 2fdb079

Browse files
Initial commit
0 parents  commit 2fdb079

24 files changed

+4939
-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,package.json}]
14+
indent_size = 2
15+
16+
# The indent size used in the package.json file cannot be changed:
17+
# https://github.com/npm/npm/pull/3180#issuecomment-16336516

.gitattributes

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/tests export-ignore
2+
/docs export-ignore
3+
/js-src export-ignore
4+
/.gitattributes export-ignore
5+
/.travis.yml export-ignore
6+
/.scrutinizer.yml export-ignore
7+
/.gitignore export-ignore
8+
/.editorconfig export-ignore
9+
/dependabot.yml export-ignore
10+
/.github export-ignore
11+
/phpunit.xml.dist export-ignore
12+
/phpcs.xml.dist export-ignore
13+
/node_modules export-ignore
14+
/package.json export-ignore
15+
/package-lock.json export-ignore
16+
/webpack.config.js export-ignore

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.phpunit.result.cache
2+
/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: [code/*, tests/*]

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Change Log

LICENSE

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

README.md

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Element Link option Silverstripe's Link Field
2+
=================
3+
Extension for silverstripe/linkfield that allows linking direct to elements
4+
5+
## Maintainer Contact
6+
* Ed Chipman ([UndefinedOffset](https://github.com/UndefinedOffset))
7+
8+
## Requirements
9+
* [silverstripe/framework](https://github.com/silverstripe/silverstripe-framework) ~5.0
10+
* [silverstripe/linkfield](https://github.com/silverstripe/silverstripe-linkfield) ~1.0
11+
* [sheadawson/silverstripe-dependentdropdownfield](https://github.com/sheadawson/silverstripe-dependentdropdownfield) ~3.0
12+
13+
14+
## Installation
15+
```
16+
composer require webbuilders-group/silverstripe-element-link
17+
```

_config.php

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?php

_config/config.yml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
Name: element-link
3+
After: "#linkfield"
4+
---
5+
SilverStripe\Admin\LeftAndMain:
6+
extra_requirements_javascript:
7+
- 'webbuilders-group/silverstripe-element-link: javascript/boot.js'
8+
9+
SilverStripe\LinkField\Form\AbstractLinkField:
10+
extensions:
11+
- 'WebbuildersGroup\ElementLink\Extensions\LinkFieldExtension'

composer.json

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"name": "webbuilders-group/silverstripe-element-link",
3+
"description": "Extension for silverstripe/linkfield that allows linking direct to elements",
4+
"type": "silverstripe-vendormodule",
5+
"keywords": ["silverstripe", "linkfield", "links", "elemental", "blocks"],
6+
"license": "BSD-3-Clause",
7+
"authors": [
8+
{
9+
"name": "Ed Chipman",
10+
"homepage": "https://webbuildersgroup.com",
11+
"role": "Developer"
12+
}
13+
],
14+
"require": {
15+
"silverstripe/framework": "~5.0",
16+
"silverstripe/linkfield": "~4.0",
17+
"sheadawson/silverstripe-dependentdropdownfield": "~3.0"
18+
},
19+
"require-dev": {
20+
"squizlabs/php_codesniffer": "~3.4"
21+
},
22+
"extra": {
23+
"expose": [
24+
"javascript"
25+
]
26+
},
27+
"support": {
28+
"issues": "https://github.com/webbuilders-group/silverstripe-element-link/issues"
29+
},
30+
"autoload": {
31+
"psr-4": {
32+
"WebbuildersGroup\\ElementLink\\": "src/"
33+
}
34+
}
35+
}

javascript/ElementDropdownField.js

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
(function($) {
2+
$.entwine('dependentdropdown', function ($) {
3+
$('.depended-on-field .treedropdown[data-dependent-field]').entwine({
4+
Loading: false,
5+
6+
onadd: function() {
7+
const dependentField = $(this).attr('data-dependent-field');
8+
if (dependentField) {
9+
const drop = $('select[name=' + $.escapeSelector(dependentField) + ']');
10+
const depends = self.find('input[name]');
11+
12+
if (depends) {
13+
depends.change(function () {
14+
if (!this.value || this.value <= 0) {
15+
drop.disable(drop.attr('data-empty') || '');
16+
} else {
17+
drop.disable('Loading...');
18+
19+
$.get(drop.data('link'), {
20+
val: this.value,
21+
},
22+
function (data) {
23+
drop.enable();
24+
25+
if (drop.attr('data-empty')) {
26+
drop.append($('<option />').val('').text(drop.attr('data-empty')));
27+
}
28+
29+
if (data.length > 0) {
30+
$.each(data, function () {
31+
drop.append($('<option />').val(this.k).text(this.v));
32+
});
33+
} else {
34+
drop.disable(drop.attr('data-empty') || '');
35+
}
36+
37+
drop.trigger('liszt:updated').trigger('chosen:updated').trigger('change');
38+
});
39+
}
40+
});
41+
42+
if (!depends.val() || depends.val() <= 0) {
43+
drop.disable(drop.attr('data-empty') || '');
44+
}
45+
}
46+
}
47+
},
48+
});
49+
});
50+
})(jQuery);

javascript/boot.js

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

javascript/boot.js.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js-src/boot/boot.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/* global jQuery */
2+
import Injector from 'lib/Injector';
3+
import ElementDropdownField from '../components/ElementDropdownField';
4+
5+
document.addEventListener('DOMContentLoaded', () => {
6+
Injector.component.register('ElementDropdownField', ElementDropdownField);
7+
8+
Injector.transform(
9+
'element-link',
10+
(updater) => {
11+
updater.form.alterSchema(
12+
'Link.EditingLinkInfo',
13+
(form) =>
14+
form
15+
.updateField('PageID', {
16+
onChange: function(value) {
17+
// Workaround to get ElementDropdownField working
18+
jQuery('input[name=PageID]').val(value).trigger('change', value);
19+
},
20+
})
21+
.getState()
22+
);
23+
}
24+
);
25+
});

0 commit comments

Comments
 (0)