필드 요소가있는 사용자 지정 블록을 만드는 사용자 지정 모듈이 있습니다.Drupal 8 맞춤 블록 (모듈) 나뭇 가지 템플릿 파일을 만듭니다
이 모든 것은 정상적으로 작동하지만이 블록을 테마로해야합니다. 나는 여기의 다른 지위를 점검했고, 행운으로 시험해 보았다.
나뭇 가지 디버그를 사용하도록 설정하고 테마 제안을 받았습니다. 아직도 운이 없다.
누구나 올바른 방향으로 나를 가리킬 수 있습니까?
이
내가 지금까지 무엇을 가지고 :my_module/my_module.module을
// nothing related in here
my_module/SRC/플러그인/차단/myModuleBlock.php
<?php
namespace Drupal\my_module\Plugin\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Form\FormStateInterface;
/**
* Provides a 'ModuleBlock' block.
*
* @Block(
* id = "module_block",
* admin_label = @Translation("My Module"),
*)
*/
class ModuleBlock extends BlockBase {
public function blockForm($form, FormStateInterface $form_state) {
$form['test'] = array(
'#type' => 'select',
'#title' => $this->t('test'),
'#description' => $this->t('test list'),
'#options' => array(
'Test' => $this->t('Test'),
),
'#default_value' => isset($this->configuration['test']) ? $this->configuration['test'] : 'Test',
'#size' => 0,
'#weight' => '10',
'#required' => TRUE,
);
return $form;
}
/**
* {@inheritdoc}
*/
public function blockSubmit($form, FormStateInterface $form_state) {
$this->configuration['test'] = $form_state->getValue('test');
}
/**
* {@inheritdoc}
*/
public function build() {
$build = [];
$build['module_block_test']['#markup'] = '<p>' . $this->configuration['test'] . '</p>';
return $build;
}
}
my_module/templates/block - my-module.html.twig // 나뭇 가지가 제안하는대로 디버그
<h1>This is a test</h1>
<div id="test-widget">{{ content }}</div>
나는 또한 내 my_theme.theme에 내가 이것을 가지고 있지만 내가 돈주의해야한다 t이 생각하는 그 관련 :
public function build() {
return array(
'#theme' => 'block--my-module'
);
}
:
에 관해서는
// Add content type suggestions.
function my_theme_theme_suggestions_page_alter(array &$suggestions, array $variables) {
if ($node = \Drupal::request()->attributes->get('node')) {
array_splice($suggestions, 1, 0, 'page__node__' . $node->getType());
}
}
는 내가 해봤 것은 이것이다
하지만 여전히가 없습니다.
여기에 도움을 주시면 매우 감사하겠습니다.
업데이트 : 그래서 방금 작동했지만 아직 도움이 필요합니다. block--my-module.html.twig
템플릿을 내 테마 디렉토리로 옮겼습니다.
모듈 디렉토리에서 어떻게 작동합니까?
파일이'myModuleBlock.php'이지만 의도적으로 클래스는'my'없이'ModuleBlock'입니까? 비표준 것 같습니다. –