@@ -96,6 +96,7 @@ public static function get_snippet_scss($path, $source) {
96
96
* Get a snippet defined in the code based on path.
97
97
*
98
98
* @param string $path
99
+ * @param string $source
99
100
*
100
101
* @return mixed
101
102
*/
@@ -105,16 +106,20 @@ public static function get_snippet_meta($path, $source) {
105
106
// Get the snippets file, based on the source.
106
107
$ file = self ::get_snippet_file ($ path , $ source );
107
108
109
+ // If the file does not exist or is not readable, we can not proceed.
108
110
if (is_null ($ file )) {
109
- return ;
111
+ return null ;
110
112
}
111
113
114
+ // Extract the meta from the SCSS files top level multiline comment in WordPress style.
112
115
$ headers = self ::get_snippet_meta_from_file ($ file );
113
116
117
+ // The title is the only required meta-key that actually must be set.
114
118
if (!array_key_exists ('Snippet Title ' , $ headers )) {
115
119
return null ;
116
120
}
117
121
122
+ // Create an object containing the information.
118
123
$ snippet = new \stdClass ();
119
124
$ snippet ->title = $ headers ['Snippet Title ' ];
120
125
$ snippet ->description = $ headers ['Description ' ];
@@ -126,18 +131,23 @@ public static function get_snippet_meta($path, $source) {
126
131
}
127
132
128
133
/**
129
- * Compose snippets file data to record.
134
+ * Combine snippets meta data from the snippets file with the database record.
135
+ *
136
+ * This is currently used for create the view for the settings table.
130
137
*
131
- * @param mixed $data
138
+ * @param moodle_recordset $snippetrecordset
132
139
*
133
140
* @return array
134
141
*/
135
142
public static function compose_snippets_data ($ snippetrecordset ) {
136
143
$ snippets = [];
137
144
138
145
foreach ($ snippetrecordset as $ snippetrecord ) {
146
+ // Get the meta information from the SCSS files top multiline comment.
139
147
$ snippet = self ::get_snippet_meta ($ snippetrecord ->path , $ snippetrecord ->source );
148
+ // If snippets meta is not found, it will no be added to the returned snippet array.
140
149
if ($ snippet ) {
150
+ // Merge the two objects.
141
151
$ snippets [] = (object ) array_merge ((array ) $ snippetrecord , (array ) $ snippet );
142
152
}
143
153
}
0 commit comments