1+ <?php
2+
3+ namespace Drupal \patternlab \PatternkitController ;
4+
5+ /**
6+ * Controller routines for block example routes.
7+ */
8+ class PatternkitController {
9+ /**
10+ * @file
11+ * Provides the admin settings form for Patternkit.
12+ */
13+
14+ /**
15+ * Drupal Form API callback for the admin form.
16+ *
17+ * @param array $form
18+ * Drupal Form API form array.
19+ * @param array $form_state
20+ * Drupal Form API form state array.
21+ *
22+ * @return array
23+ * A Drupal Form API admin form array.
24+ */
25+ function patternkit_config_form (array $ form , array &$ form_state ) {
26+ $ libraries = patternkit_pattern_libraries ();
27+ $ library_options = array ();
28+ $ library_values = array ();
29+ foreach ($ libraries as $ library ) {
30+ $ lib_title = $ library ->getTitle ();
31+ $ lib_desc = $ lib_title ;
32+ $ lib_metadata = $ library ->getMetadata ();
33+ if (!empty ($ lib_metadata )) {
34+ $ library_values [] = $ lib_title ;
35+ $ lib_desc = t ('@title (@count patterns) ' , array (
36+ '@title ' => $ lib_title ,
37+ '@count ' => count ($ lib_metadata ),
38+ ));
39+ }
40+ $ library_options [$ lib_title ] = $ lib_desc ;
41+ }
42+ $ form ['patternkit_libraries ' ] = array (
43+ '#type ' => 'checkboxes ' ,
44+ '#title ' => t ('Enabled Patternkit Libraries ' ),
45+ '#options ' => $ library_options ,
46+ '#default_value ' => $ library_values ,
47+ '#disabled ' => TRUE ,
48+ );
49+
50+ $ form ['patternkit_pl_host ' ] = array (
51+ '#type ' => 'textfield ' ,
52+ '#title ' => t ('PatternLab/Kit REST Services Host ' ),
53+ '#default_value ' => variable_get ('patternkit_pl_host ' ,
54+ 'http://localhost:9001 ' ),
55+ '#size ' => '120 ' ,
56+ '#maxlength ' => '1023 ' ,
57+ );
58+
59+ $ form ['patternkit_cache_enabled ' ] = array (
60+ '#type ' => 'checkbox ' ,
61+ '#title ' => t ('Use the Patternkit Library Cache ' ),
62+ '#default_value ' => variable_get ('patternkit_cache_enabled ' , TRUE ),
63+ );
64+
65+ $ form ['patternkit_render_cache ' ] = array (
66+ '#type ' => 'checkbox ' ,
67+ '#title ' => t ('Use the Patternkit Disk Render Cache ' ),
68+ '#default_value ' => variable_get ('patternkit_render_cache ' , FALSE ),
69+ );
70+
71+ $ form ['patternkit_default_module_ttl ' ] = array (
72+ '#type ' => 'textfield ' ,
73+ '#title ' => t ('Patternkit Default Pattern TTL (in ms) ' ),
74+ '#default_value ' => variable_get ('patternkit_default_module_ttl ' ,
75+ PATTERNKIT_DEFAULT_TTL ),
76+ );
77+
78+ $ form ['#submit ' ][] = 'patternkit_config_form_submit ' ;
79+
80+ return system_settings_form ($ form );
81+ }
82+
83+ /**
84+ * Rebuilds Patternkit data on form save.
85+ *
86+ * @param array $form
87+ * Drupal Form API form array.
88+ * @param array $form_state
89+ * Drupal Form API form state array.
90+ *
91+ * @see system_settings_form_submit()
92+ */
93+ function patternkit_config_form_submit (array $ form , array &$ form_state ) {
94+ if ($ form_state ['values ' ]['patternkit_cache_enabled ' ]
95+ && !variable_get ('patternkit_cache_enabled ' , TRUE )) {
96+ $ libraries = patternkit_pattern_libraries ();
97+ foreach ($ libraries as $ library ) {
98+ $ library ->getCachedMetadata (NULL , TRUE );
99+ }
100+ }
101+
102+ drupal_set_message (t ('Rebuilt Patternkit Library Cache. ' ));
103+ }
104+ }
0 commit comments