Extensible BBCode  8.x-3.x-dev
 All Classes Namespaces Files Functions Variables
xbbcode.module
Go to the documentation of this file.
1 <?php
2 
3 /**
4  * @file
5  * The main module file containing hook implementations.
6  */
7 
8 use Drupal\Core\Render\Element;
9 
10 /**
11  * Regular expression matching any quote delimiter, including escaped quotes.
12  */
13 define('XBBCODE_RE_QUOTE', '"|\'|&(quot|#039);|');
14 
15 /**
16  * Regular expression pattern for parsing a key=value assignment.
17  */
18 define('XBBCODE_RE_ATTR', '(?:\s+(?<key>\w+)=(?<aq>' . XBBCODE_RE_QUOTE . ')(?<value>[^"]*?)\g{aq}(?=\s|\]|$))');
19 
20 /**
21  * Regular expression pattern for parsing a complete tag element.
22  */
23 define('XBBCODE_RE_TAG', '/\[(?<closing>\/)?(?<name>\w+)(?:=(?<bq>' . XBBCODE_RE_QUOTE . ')(?<option>.*?)\g{bq}(?=\s|\])|(?<attrs>' . XBBCODE_RE_ATTR . '+))?\]/i');
24 
25 /**
26  * Implements hook_theme().
27  */
28 function xbbcode_theme() {
29  return [
30  'xbbcode_plugin_selection' => [
31  'render element' => 'fieldset',
32  'function' => 'theme_xbbcode_plugin_selection',
33  ],
34  'xbbcode_tag_list' => [],
35  ];
36 }
37 
38 /**
39  * Renders the plugin selection subform as a table.
40  */
41 function theme_xbbcode_plugin_selection($variables) {
42  $fieldset = $variables['fieldset'];
43  $table = &$fieldset['tags'];
44  $extra = &$fieldset['extra']['tags'];
45 
46  $table['#attributes']['id'] = 'xbbcode-plugins';
47 
48  foreach (array_keys($table['#options']) as $tag) {
49  $table['#options'][$tag]['name']['data'] = drupal_render($extra[$tag]);
50  }
51  ksort($table['#options']);
52 
53  $html = drupal_render($table);
54  foreach (Element::children($fieldset) as $element) {
55  $html .= drupal_render($fieldset[$element]);
56  }
57  return $html;
58 }
const XBBCODE_RE_QUOTE
Definition: xbbcode.module:13
const XBBCODE_RE_ATTR
Definition: xbbcode.module:18
theme_xbbcode_plugin_selection($variables)
Definition: xbbcode.module:41
xbbcode_theme()
Definition: xbbcode.module:28