-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathJavaScriptFile.php
More file actions
59 lines (46 loc) · 1.28 KB
/
JavaScriptFile.php
File metadata and controls
59 lines (46 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
namespace DrupalCodeBuilder\Generator;
use CaseConverter\CaseString;
use DrupalCodeBuilder\Definition\PropertyDefinition;
/**
* JavaScript asset file generator.
*
* Most of the work is done in Library[CSS/JS]Asset.
*/
class JavaScriptFile extends AssetFile {
/**
* {@inheritdoc}
*/
public static function getPropertyDefinition(): PropertyDefinition {
$definition = parent::getPropertyDefinition();
$definition->addProperties([
'readable_name' => PropertyDefinition::create('string')
->setAutoAcquiredFromRequester(),
]);
return $definition;
}
/**
* Build the code files.
*/
public function getFileInfo() {
$camel_name = CaseString::snake($this->component_data['root_component_name'])->camel();
$body = <<<EOT
/**
* @file
* Defines Javascript behaviors for the {$this->component_data['readable_name']} module.
*/
(function ($, Drupal, drupalSettings) {
'use strict';
Drupal.behaviors.{$camel_name} = {
attach: function (context, settings) {
}
};
})(jQuery, Drupal, drupalSettings);
EOT;
return [
'path' => '', // Means base folder.
'filename' => $this->component_data['filename'],
'body' => [$body],
];
}
}