Skip to content

Commit 31f5fc0

Browse files
tporadowskidregad
authored andcommitted
Configure fields on Global Snippets/Configuration
Textareas where Snippets are available can now be easily selected on Manage/Global Snippets/Configuration page. Signed-off-by: Damien Regad <[email protected]> Changes to original commit: whitespace
1 parent 4155c9f commit 31f5fc0

File tree

7 files changed

+50
-9
lines changed

7 files changed

+50
-9
lines changed

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,8 @@ current position. If text is currently selected, the Snippet will replace the
6060
selection.
6161

6262
By default only the *Bug Note* field is configured to use Snippets.
63-
Other text fields (*Description*, *Steps To Reproduce* as well as *Additional
64-
Information*) can be setup to use Snippets via configuration option `plugin_Snippets_textarea_names`
65-
where you can list names of fields you are interested in, i.e. `bugnote_text, steps_to_reproduce, body` (`body`
66-
refers to text area on *Send reminder* page).
63+
Other *text* fields (*Description*, *Steps To Reproduce* as well as *Additional
64+
Information*) can be setup to use Snippets via configuration page `Manage > Global Snippets > Configuration`.
6765

6866
## Support
6967

Snippets/Snippets.API.php

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@ function xmlhttprequest_plugin_snippets() {
3737

3838
# split names of textareas found in "plugin_Snippets_textarea_names" option and
3939
# make an array of "textarea[name='FIELD_NAME']" strings
40-
$textareaSelectors = array_map(function($name) {
40+
$textareaSelectors = array_map(
41+
function($name) {
4142
return "textarea[name='$name']";
42-
}, preg_split("/[,;\s]+/", plugin_config_get("textarea_names", "bugnote_text"))
43+
},
44+
Snippet::get_configured_field_names()
4345
);
4446

4547
$data = array(
@@ -59,6 +61,7 @@ function xmlhttprequest_plugin_snippets() {
5961
plugin_pop_current();
6062
}
6163

64+
6265
/**
6366
* Object representing a saved block of text.
6467
*/
@@ -343,5 +346,26 @@ public static function global_url($p_is_global = true) {
343346
}
344347
return '';
345348
}
346-
}
347349

350+
/**
351+
* Returns an array with names of form fields (text areas) where snippets should be
352+
* available for selection.
353+
*/
354+
public static function get_configured_field_names() {
355+
return preg_split("/[,;\s]+/", plugin_config_get("textarea_names", "bugnote_text"));
356+
}
357+
358+
/**
359+
* Returns an array of ('text area field name' => 'language resource identifier') pairs
360+
* that describe available (supported) text areas. Values will be passed to lang_get().
361+
*/
362+
public static function get_available_field_names() {
363+
return array(
364+
'bugnote_text' => 'bugnote',
365+
'description' => 'description',
366+
'steps_to_reproduce' => 'steps_to_reproduce',
367+
'additional_information' => 'additional_information',
368+
'body' => 'reminder'
369+
);
370+
}
371+
}

Snippets/lang/strings_english.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,4 @@ $s_plugin_Snippets_pattern_help = '
5454
</table>
5555
';
5656

57+
$s_plugin_Snippets_textarea_names = 'Use Snippets For';

Snippets/lang/strings_french.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,4 @@ $s_plugin_Snippets_pattern_help = '
5454
</table>
5555
';
5656

57+
$s_plugin_Snippets_textarea_names = 'Utiliser Bribes Pour';

Snippets/lang/strings_german.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,5 @@ $s_plugin_Snippets_pattern_help = '
5353
<tr><td><strong>%p</strong></td><td>Projektname</td></tr>
5454
</table>
5555
';
56+
57+
$s_plugin_Snippets_textarea_names = 'Verwende Textbausteinen in';

Snippets/pages/config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function maybe_set_option( $name, $value ) {
1616
maybe_set_option("edit_global_threshold", gpc_get_int("edit_global_threshold"));
1717
maybe_set_option("use_global_threshold", gpc_get_int("use_global_threshold"));
1818
maybe_set_option("edit_own_threshold", gpc_get_int("edit_own_threshold"));
19+
maybe_set_option("textarea_names", implode(",", gpc_get_string_array("textarea_names", '')));
1920

2021
form_security_purge("plugin_Snippets_config");
2122
print_successful_redirect(plugin_page("config_page", true));
22-

Snippets/pages/config_page.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,22 @@
3434
<td><select name="edit_own_threshold"><?php print_enum_string_option_list( 'access_levels', plugin_config_get( 'edit_own_threshold' ) ) ?></select></td>
3535
</tr>
3636

37+
<tr <?php echo helper_alternate_class() ?>>
38+
<td class="category"><?php echo plugin_lang_get( 'textarea_names' ) ?></td>
39+
<td>
40+
<?php
41+
$configuredNames = Snippet::get_configured_field_names();
42+
$availableNames = Snippet::get_available_field_names();
43+
44+
foreach( $availableNames as $name => $lang_get_param ) {
45+
echo '<div><label><input type="checkbox" name="textarea_names[]" value="', $name, '" ';
46+
check_checked( in_array($name, $configuredNames) );
47+
echo '/>', lang_get( $lang_get_param ), "</label></div>\n";
48+
}
49+
?>
50+
</td>
51+
</tr>
52+
3753
<tr>
3854
<td class="center" colspan="2"><input type="submit" value="<?php echo plugin_lang_get("action_update") ?>"/></td>
3955
</tr>
@@ -43,4 +59,3 @@
4359

4460
<?php
4561
html_page_bottom();
46-

0 commit comments

Comments
 (0)