Файл.theme не доступен для всех хуков и предварительная обработка не реализована
Так что я пытаюсь реализовать тему в Drupal 8, я хотел исключить кнопку поиска из формы поиска. Но когда я пытаюсь использовать hook_form_alter, в моем файле.theme ничего не достигается, и я не могу придумать причину, насколько я могу сказать, что весь мой синтаксис правильный. Даже если это не правильно, операторы die и var_dump должны как минимум выводить что-то, но в настоящее время это не так.
Я изменил тему по умолчанию на drupal8_zymphonies_theme, и в этой теме задействованы хуки, поэтому я считаю, что должна быть какая-то настройка, которую нужно изменить. При этом тема zymphonies находится в этой структуре /theme/drupa8_zymphonies_theme, в то время как моя тема endymion - theme/custom/endymion. Не уверен, что это имеет значение, но я думаю, что упомянул бы об этом.
/**
* @file
* Contains theme override functions and preprocess functions
*/
var_dump('another hello');
die('hello there');
use Drupal\Core\Template\RenderWrapper;
use Drupal\search\Form\SearchBlockForm;
use Drupal\Core\Form\FormStateInterface;
function endymion_form_search_block_form_alter(SearchBlockForm &$form, FormStateInterface &$form_state, $form_id) {
//Remove the search box from the form to make the look a little cleaner
$logger = \Drupal::logger('endymion');
$logger->debug(''. print_R($form, true) . 'search form');
if ($form_id == 'search_block_form') {
$logger->debug(''. print_R($form, true) . 'search form');
$form['actions']['#attributes']['class'][] = 'element-invisible';
$form['search_block_form']['#size'] = 40; // define size of the textfield
$form['search_block_form']['#default_value'] = t('Search'); // Set a default value for the textfield
// Add extra attributes to the text box
$form['search_block_form']['#attributes']['onblur'] = "if (this.value == '') {this.value = 'Search';}";
$form['search_block_form']['#attributes']['onfocus'] = "if (this.value == 'Search') {this.value = '';}";
// Prevent user from searching the default text
$form['#attributes']['onsubmit'] = "if(this.search_block_form.value=='Search'){ alert('Please enter a search'); return false; }";
// Alternative (HTML5) placeholder attribute instead of using the javascript
$form['search_block_form']['#attributes']['placeholder'] = t('Search');
}
}