Drupal custom module(최종) 두루팔 사용자 정의 모듈 생성
helloworld 모듈 생성
xampp v.3.3.0 + drupal11
1. module 파일 생성
xampp > htdocs > drupal > modules > custom > helloworld
helloworld.info.yml
-------------------------------------------------------------------------------------------------------
File content: hello_world.info.yml
-------------------------------------------------------------------------------------------------------
name: Hello World
type: module
description: 'First custom drupal module'
core_version_requirement: ^11
package: Custom
---------------------------------------------------------------------------------------------------------
helloworld.routing.yml
-------------------------------------------------------------------------------------------------------
File content: helloworld.routing.yml
-------------------------------------------------------------------------------------------------------
helloworld.page:
path: '/helloworld'
defaults:
_controller: '\Drupal\helloworld\Controller\HelloController::content'
_title: 'Hello World'
requirements:
_permission: 'access content'
---------------------------------------------------------------------------------------------------------
2. xampp > htdocs > drupal > modules > custom > helloworld > config > install
helloworld.settings.yml
-------------------------------------------------------------------------------------------------------
File content: helloworld.settings.yml
-------------------------------------------------------------------------------------------------------
name: '@Drupal Test'
---------------------------------------------------------------------------------------------------------
3. xampp > htdocs > drupal > modules > custom > helloworld > src > Cotroller
HelloController.php
-------------------------------------------------------------------------------------------------------
File content: HelloController.php
-------------------------------------------------------------------------------------------------------
<?php
/**
* @file
* Contains \Drupal\helloworld\Cotroller\HelloController.
*/
namespace Drupal\helloworld\Controller;
use Drupal\core\Controller\ControllerBase;
/**
* Defines HelloController class.
*/
class HelloController extends ControllerBase {
/**
* Display the markup.
* @return
*/
public function content() {
return [
'#type' => 'markup',
'#markup' => $this->t('Hello, World'),
];
}
}
---------------------------------------------------------------------------------------------------------
2. install
Extend > Custom > 생성 모듈 선택 > install
3. 모듈 삭제
- 생성한 사용자 모듈 폴더 삭제
- Apache/Tomcat 다운
- Configuration > Development > Development settings > Twig development mode 해제, 'Do not cache markup' 해제
- 다른 예제
- 구조
>Drupal
>> core
>>modules
>>> custom
>>>> hello_world
>>>>> src
---- hello_world.info.yml
---- hello_world.links.menu.yml(X)
---- hello_world_routing.yml
>>>>> src
>>>>>> Controller
------- HelloController.php
>>>>> config
>>>>>> install
------- hello_world.settings.yml
---------------------------------------------------------------------------------------------------------
File content: hello_world.links.menu.yml
----------------------------------------------------------------------------------------------------------
hello_world.admin:
title: 'Hello module settings'
description: 'example of how to make an admin settings page link'
parent: system.admin_config_development
route_name: hello_world.hello_world
weight: 100
-----------------------------------------------------------------------------------------------------------
참고자료: https://www.drupal.org/docs/creating-custom-modules/step-by-step-tutorial-hello-world