Я наконец погрузился в Drupal 8 для проекта. Однако в моем модуле я не могу понять, как визуализировать шаблон из моего модуля на основе маршрута.
В Drupal 7 я бы обычно делал это
custom.module
function union_views_menu() {
$items = array();
$items['home'] = array(
'title' => 'Home',
'description' => 'home apge',
'page callback' => 'home_page',
'access arguments' => array( 'access content'),
'type' => MENU_CALLBACK
);
return $items;
}
function home_page() {
return theme('home_page');
}
function union_views_theme(){
return array(
'home_page' => array(
'template' => 'templates/home-page'
)
);
}
И тогда у меня был бы шаблон в папке templates
С Drupal 8 я примерно здесь:
custom.routing.yml
custom:
path: /home
defaults:
_controller: Drupal\custom\Controller\CustomController::custom
requirements:
_permission: 'access content'
src / Controller / CustomController.php
namespace Drupal\custom\Controller;
class CustomController {
public function custom(){
return array(
'#title' => 'Custom Theme',
'#markup' => 'This is a content.'
);
}
}
И все работает отлично, чтобы добраться до маршрута. Но я не могу понять, как создать функцию hook_theme для моего hook_menu, чтобы использовать ее в качестве обратного вызова.