-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathJavaScriptFile.php
More file actions
55 lines (43 loc) · 1.25 KB
/
JavaScriptFile.php
File metadata and controls
55 lines (43 loc) · 1.25 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
<?php
namespace DrupalCodeBuilder\Generator;
use DrupalCodeBuilder\File\CodeFile;
use MutableTypedData\Definition\PropertyListInterface;
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 addToGeneratorDefinition(PropertyListInterface $definition) {
parent::addToGeneratorDefinition($definition);
$definition->addProperties([
'readable_name' => PropertyDefinition::create('string')
->setAutoAcquiredFromRequester(),
]);
}
/**
* {@inheritdoc}
*/
public function getFileInfo(): CodeFile {
$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 new CodeFile([$body]);
}
}