Skip to content

Commit a64fa7d

Browse files
Merge pull request #45 from sachbearbeiter/main
MISC features
2 parents 506421b + 7e41b62 commit a64fa7d

File tree

14 files changed

+227
-32
lines changed

14 files changed

+227
-32
lines changed

README.md

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ If you prefer to use a foreach to create the menu, or if you are upgrading from
8383
<ul>
8484
<?php foreach($items as $item): ?>
8585
<li>
86-
<a href="<?php echo $item->url(); ?>" <?php e($item->isOpen(), 'aria-current') ?>>
86+
<a href="<?php echo $item->url(); ?>" <?php e($item->isOpen(), 'aria-current="page"') ?>>
8787
<?php echo Str::esc($item->text(), 'html') ?>
8888
</a>
8989
<?php if($item->children()->isNotEmpty()): ?>
@@ -118,7 +118,7 @@ This means that if you simply add 5 Kirby pages to the field in multilang mode a
118118

119119
The plugin allows you to add "Kirby Pages" and "Custom Links" to the navigation field. For "Kirby Pages", the page title will be the default value of the link text, if no custom link text is entered. This means that if you simply add 5 Kirby pages to the field in multilang mode and don't edit the links, you will see the language-specific page title and page URL in the generated markup.
120120

121-
## What is new in version 4.0?
121+
## What's new in version 4.0?
122122

123123
Changes worth mentioning:
124124
- It works with Kirby 4
@@ -131,6 +131,34 @@ Changes worth mentioning:
131131
- Markup: the current language and the actual values of the page title and page URL are taken into account when generating the markup for the field in the template.
132132
- Markup: link text and link attributes are properly escaped to prevent potential issues
133133

134+
## What's new in version 4.1?
135+
136+
New features:
137+
- The 'class' and 'target' values of links are now editable
138+
- The 'anchor' values of 'Kirby page' links are now editable
139+
- The 'title' textfield can be hidden, if you do not need it
140+
- The 'popup' toggle can be hidden, if you do not need it
141+
142+
Different sites have different needs, so the editable fields are configurable via /site/config/config.php.
143+
144+
Here are the available options that you can use in your config.php, and their default values:
145+
146+
```php
147+
return [
148+
'chrisbeluga.navigation.edit_title' => TRUE,
149+
'chrisbeluga.navigation.edit_popup' => TRUE,
150+
'chrisbeluga.navigation.edit_target' => FALSE,
151+
'chrisbeluga.navigation.edit_class' => FALSE,
152+
'chrisbeluga.navigation.edit_anchor' => FALSE,
153+
];
154+
```
155+
156+
For example, if you want to customize the 'target' value of your links, then set 'chrisbeluga.navigation.edit_target' to TRUE. This will replace the simple 'Popup' toggle with a 'Target' textfield, allowing you to set a link target, such as '_parent' or '_top'.
157+
158+
If you want to add an anchor value to your 'Kirby page' links, for example to have an URL such as /en/contact#locations, set 'chrisbeluga.navigation.edit_anchor' to TRUE. You can enter 'locations' as anchor, and '#locations' will be appended to the page URL of the link.
159+
160+
If you use the recommended way to output the navigation markup from your template (such as $site->navigation()->toNavigationMarkup() in case of a field called 'navigation'), then any target, class and anchor values will be included automatically in the generated markup.
161+
134162
## Contributing
135163

136164
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

composer.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "chrisbeluga/kirby-navigation",
33
"description": "Kirby 4 field for hierarchical menus with drag & drop level indentation.",
44
"type": "kirby-plugin",
5-
"version": "4.0.3",
5+
"version": "4.1.0",
66
"license": "MIT",
77
"homepage": "https://github.com/chrisbeluga/kirby-navigation",
88
"authors": [
@@ -15,7 +15,14 @@
1515
"name": "Ahmet Bora",
1616
"email": "[email protected]",
1717
"homepage": "https://owebstudio.com/"
18-
}
18+
},
19+
{
20+
"name": "Gabor Horvath"
21+
},
22+
{
23+
"name": "Immo Seebörger",
24+
"homepage": "https://diesachbearbeiter.de/"
25+
}
1926
],
2027
"require": {
2128
"getkirby/composer-installer": "^1.2"

config/api.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@
6666
// Default values of page links that prop.php also provides
6767
$language_code . '_link_text' => '',
6868
$language_code . '_link_title' => '',
69-
'popup' => false,
7069
'children' => [],
70+
'target' => '',
7171
// Temporary helper values that will not be saved
7272
'count' => $item->index()->count(),
7373
]);

config/methods.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,23 @@
1313
// Use anonymous recursive function to process child items
1414
$process_item = function($item, $depth=1) use (&$process_item, $lang_code) {
1515
$item['depth']=$depth;
16-
// To help markup generation, set 'url', 'text' and 'title'
17-
// according to the current language
16+
// To help markup generation, set 'url', 'text', 'title'
17+
// and the optional 'anchor' according to the current language
1818
if ($item['type']=='page') {
1919
$item['url']=$item[$lang_code . '_page_url'];
2020
$item['text']=$item[$lang_code . '_link_text'];
2121
$item['title']=$item[$lang_code . '_link_title'];
22+
if (isset($item[$lang_code . '_link_anchor'])) {
23+
$item['anchor']='#' . $item[$lang_code . '_link_anchor'];
24+
}
25+
else {
26+
$item['anchor']='';
27+
}
2228
if ($item['text']=='') {
23-
$item['text']=$item[$lang_code . '_page_title'];
29+
$item['text']=$item[$lang_code . '_page_title'];
2430
}
2531
if ($item['title']=='') {
26-
$item['title']=$item[$lang_code . '_page_title'];
32+
$item['title']=$item[$lang_code . '_page_title'];
2733
}
2834
}
2935
elseif ($item['type']=='custom') {
@@ -32,6 +38,7 @@
3238
}
3339
else {
3440
$item['error']=TRUE;
41+
return $item;
3542
}
3643
if ($item['title']==$item['text']) {
3744
// No need to have a title
@@ -44,8 +51,11 @@
4451
if ($item['title']!='') {
4552
$item['attributes']['title']=$item['title'];
4653
}
47-
if (!empty($item['popup'])) {
48-
$item['attributes']['target']='_blank';
54+
if (isset($item['class']) && ($item['class']!=='')) {
55+
$item['attributes']['class']=$item['class'];
56+
}
57+
if (isset($item['target']) && ($item['target']!='')) {
58+
$item['attributes']['target']=$item['target'];
4959
}
5060
if ($item['url'] === kirby()->url('current')) {
5161
$item['attributes']['aria-current']='page';

config/props.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,25 @@
3535
}
3636
return $items;
3737
},
38+
// Notify the Vue code which textfields should be editable by default.
39+
// Notes:
40+
// - The 'Popup' will be automatically hidden, if 'Target' is visible
41+
// - If a certain value is set in the field, then Vue will show
42+
// the editable textfield even if the corresponding option is false
43+
// - These options can be set in /site/config/config.php
44+
'edit_title' => function() {
45+
return (bool) option('chrisbeluga.navigation.edit_title', true);
46+
},
47+
'edit_popup' => function() {
48+
return (bool) option('chrisbeluga.navigation.edit_popup', true);
49+
},
50+
'edit_target' => function() {
51+
return (bool) option('chrisbeluga.navigation.edit_target', false);
52+
},
53+
'edit_class' => function() {
54+
return (bool) option('chrisbeluga.navigation.edit_class', false);
55+
},
56+
'edit_anchor' => function() {
57+
return (bool) option('chrisbeluga.navigation.edit_anchor', false);
58+
}
3859
];

includes/refresh_item.inc.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* functions, when needed.
1717
*
1818
* A secondary purpose of these functions is to make multilanguage
19-
* navigation field editing as convinient as possible.
19+
* navigation field editing as convenient as possible.
2020
*/
2121

2222
// Use anonymous recursive function to process child items
@@ -118,6 +118,11 @@
118118
if (!isset($item[$language_code . '_link_title'])) {
119119
$item[$language_code . '_link_title']='';
120120
}
121+
if (option('chrisbeluga.navigation.edit_anchor')) {
122+
if (!isset($item[$language_code . '_link_anchor'])) {
123+
$item[$language_code . '_link_anchor']='';
124+
}
125+
}
121126
}
122127
elseif ($item['type']=='custom') {
123128
// Validate the URL
@@ -132,6 +137,16 @@
132137
$item[$language_code . '_link_title']='';
133138
}
134139
}
140+
// Handle the popup -> target transition to remain compatible.
141+
// Previous plugin versions used the 'popup' boolean value.
142+
// The new version uses the 'target' string value.
143+
// The new version uses the 'Popup' toggle UI by default,
144+
// but provides the edit_target option to switch to 'Target' string UI.
145+
if (isset($item['popup']) && !isset($item['target'])) {
146+
$item['target']=$item['popup'] ? '_blank' : '';
147+
}
148+
unset($item['popup']);
149+
135150
// refresh child items, if any
136151
if (!empty($item['children'])) {
137152
foreach (array_keys($item['children']) as $key) {

index.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,11 @@
2121
'navigation_item' => __DIR__ . '/snippets/navigation_item.php',
2222
],
2323
'fieldMethods' => require_once __DIR__ . '/config/methods.php',
24+
'options' => [
25+
'edit_title' => TRUE,
26+
'edit_popup' => TRUE,
27+
'edit_target' => FALSE,
28+
'edit_class' => FALSE,
29+
'edit_anchor' => FALSE,
30+
],
2431
]);

languages/de.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
'editor.label.url' => 'Url',
1111
'editor.label.text' => 'Text',
1212
'editor.label.title' => 'Titel',
13+
'editor.label.anchor' => 'Anker',
14+
'editor.label.class' => 'Klasse',
15+
'editor.label.target' => 'Ziel',
1316
'editor.label.popup' => 'Popup',
1417
'editor.menu.close' => 'Schließen',
1518
'editor.menu.edit' => 'Bearbeiten',

languages/en.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
'editor.label.url' => 'Url',
1111
'editor.label.text' => 'Text',
1212
'editor.label.title' => 'Title',
13+
'editor.label.anchor' => 'Anchor',
14+
'editor.label.class' => 'Class',
15+
'editor.label.target' => 'Target',
1316
'editor.label.popup' => 'Popup',
1417
'editor.menu.close' => 'Close Item',
1518
'editor.menu.edit' => 'Edit Item',

0 commit comments

Comments
 (0)