8. 1. Как сбросить кеш?
drush rebuild или /rebuild.php
drush cc тоже работает:
> drush cc render
9. 2. Ошибка “The provided host name is not
valid for this server”
Вместо $base_url теперь
$settings['trusted_host_patterns'] = array(
'^example.com$',
'^.+.example.com$',
'^example.org$',
'^.+.example.org$',
);
10. 3. Конфиги хранятся в базе?
По умолчанию — да.
config.storage.active:
class: DrupalCoreConfigDatabaseStorage
config.storage.staging:
class: DrupalCoreConfigFileStorage
11. 4. Как проверить, залогинен ли юзер?
if (Drupal::currentUser()->isAnonymous()) {
// Anonymous user...
}
12. 5. Как сделать запрос к базе?
$query = Drupal::database()->select('node', 'n');
//$query->join('node_field_data', 'nf', 'n.nid = nf.nid');
//$query->condition('nf.langcode', 'en');
//$query->fields('nf');
dpm( $query->fields('n')
->execute()
->fetchAll()
);
13. 6. Как получить nid текущей ноды?
$node = Drupal::routeMatch()->getParameter('node');
if ($node) {
// You can get nid and anything else you need from
the node object.
}
aka menu_get_object()
14. 7. Как обращаться к филдам?
$node->body->value
$node->uid->entity->mail->value
// First tag.
$node->field_tags->entity->name->value
// Second tag.
$node->field_tags[1]->entity->name-
>value
15. 8. Как загрузить иерархнию
терминов?
Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadTree('tags')
16. 9. Как отрендерить блок программно?
$block =
DrupalblockEntityBlock::load('bartik_search');
$output = Drupal::entityTypeManager()
->getViewBuilder('block')
->view($block);
17. 10. Как добавить на страницу JS?
/**
* Implements hook_page_attachments().
*/
function yourmodule_page_attachments(&$page) {
// This returns TRUE for admin paths.
if (!Drupal::service('router.admin_context')->isAdminRoute()) {
$page['#attached']['library'][] = 'yourmodule/yourlibrary';
}
}
18. 11. Как __Ваш_Вопрос__?
• Настроить IDE
• Читать ядро
• Читать портированные модули и примеры
• Читать дайджест