@pingvin156

Как подключить js и новый блок через собственный модуль в Drupal8?

Здравствуйте. Помогите, пожалуйста, разобраться с добавлением js и блоков через собственный блок. Сам модуль активируется в настройках Друпала. Вот что имеется в папке LotteryList:
файл LotteryList.module:
<?php
/**
* @file
* Code for the Chad module.
*/

?>

файл LotteryList.info.yml
name: LotteryList Block
description: A simple module to demonstrate Block.
core: 8.x
package: Custom
dependencies:
- node
- block
type: module

файл LotteryList.libraries.yml:
global-styling:
version: 1.x
js:
js/custom.js: {}
dependencies:
- core/jquery
- core/jquery.once

Файл блока в папке модуля \src\Plugin\Block\LotteryListBlock.php
<?php
/**
* @file
* Contains \Drupal\LotteryList\Plugin\Block\LotteryListBlock.
*/

namespace Drupal\LotteryList\Plugin\Block;

use Drupal\Core\Block\BlockBase;

/**
* Provides a 'LotteryList' block.
*
* @Block(
* id = "lotterylist_block",
* admin_label = @Translation("LotteryList block"),
* category = @Translation("Custom LotteryList block")
* )
*/
class LotteryListBlock extends BlockBase {

/**
* {@inheritdoc}
*/
public function build() {
return array(
'#type' => 'markup',
'#markup' => 'LotteryList',
);
}
}

В папке js файл custom.js:
(function ($) {
Drupal.behaviors.myModuleBehavior = {
attach: function (context, settings) {
$(context).find('.click-me').once('myCustomBehavior').click(function () {
alert('Hello, World!');
});
}
};
})(jQuery);

Помогите, пожалуйста, разобраться... Заранее спасибо!
  • Вопрос задан
  • 220 просмотров
Пригласить эксперта
Ответы на вопрос 1
@WiseUkraine
1. Закиньте папку с модулем в site_folder/modules/custom (если "custom" нету создайте)
2. В админке включите модуль!
3. Profit!
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы