ใช้กับ php 7.4
wget https://github.com/drush-ops/drush/releases/download/8.3.5/drush.phar
chmod +x drush.phar && mv drush.phar /usr/local/bin/drush
ใช้กับ php 7.4
wget https://github.com/drush-ops/drush/releases/download/8.3.5/drush.phar
chmod +x drush.phar && mv drush.phar /usr/local/bin/drush
แก้ไขที่ .theme ใน folder Theme ของคุณ แล้ว โค้ดที่ได้จากข้างล่างนี้
(THEMENAME เปลี่ยนเป็นชื่อ Theme ของคุณเอง)
/**
* Implements hook_preprocess_html().
*/
function THEMENAME_preprocess_html(&$vars) {
// Get the current path
$current_path = \Drupal::service('path.current')->getPath();
$internal = \Drupal::service('path_alias.manager')->getAliasByPath($current_path);
// Assign it to body class
$vars['attributes']['class'][] = str_replace("/", "", $internal);
}
การทำงานกับ ไฟล์ (File entities)
วิธีส่งค่าไฟล์ออกมาด้วย fid ใน Drupal:
$fid = 31; // ตัวอย่าง fid
$file_storage = \Drupal::entityTypeManager()->getStorage('file');
$file = $file_storage->load($fid);
การแสดงค่า ออกจากตัวแปร
การทำงานเกี่ยวกับ nodes
โหลด Node โดย nid:
$nid = 123; // ตัวอย่าง nid
$node_storage = \Drupal::entityTypeManager()->getStorage('node');
$node = $node_storage->load($nid);
Get ค่า nid:
echo $node->id(); // 123
Get ค่า bundle type (หรือ content type):