繁體中文

用繁體中文寫的文章

Drupal 8編程 - 如何利用程式碼創造Entity

Submitted by saladlam on
假設要創造一個新的"article" entity(安裝standard profile時所設定的entity type)
$array = array (
	'nid' => '45',	// can designate node id
	'type' => 'article',
	'title' => 'article title',
	'uid' => '1',	// author
	'promote' => '1',	// promoted to front page
	'sticky' => '0',	// Sticky at top of lists
	'status' => '0',	// 0: unpublished, 1: publish
	'created' => '1483228800',	// timestamp
	'changed' => '1483228800',	// timestamp
	'body' => array(
		array(
			'value' => 'text',
			'summary' => 'summary of body',
			'fo

Drupal 8架站實用模組 - D8 Editor File upload

Submitted by saladlam on

功用

一個"CKEditor"的模組,提供在內文附加檔案的功能,用法就好似"Insert Image"功能一樣。

注意事項

  1. 要先在設定"CKEditor"那頁,在"TOOLBAR CONFIGURATION",把"File button"拉進去"Active toolbar"。

下載連結

https://www.drupal.org/project/editor_file

Drupal 8架站實用模組 - reCAPTCHA

Submitted by saladlam on

功用

可防止Spammer的機械人程式在comment, contact form等開放給公眾使用的地方注入大量垃圾信息。

注意事項

  1. 需要在reCAPTCHA網站註冊,並獲取"Site key"及"Secret key"。
  2. 模組已預先註冊了一些CAPTCHA Points,可以選擇是否enable它們。若果想註冊新的CAPTCHA Points,輸入Form ID就可以了。
  3. 文章comment的Form ID是"comment_comment_form"。

下載連結

https://www.drupal.org/project/recaptcha

Drupal 8批次上載圖像

Submitted by saladlam on

用Drupal的CKEditor自帶的Image upload功能,插入一大堆圖像,實在是太勞累。為了方便一次過上載一大堆圖像,寫了一個模組做以下工作。

  1. 把圖像檔案放在"public://"內的某個目錄
  2. 寫一個Controller,做
    1. 讀取目錄內的圖像檔案
    2. 用file_save_data()註冊檔案,會得到一個File content entity object
    3. 砌用來貼在文章內的html程式碼
    4. 刪除目錄內的檔案
    5. 顯示html程式碼

很簡單的程式,一兩小時內就可以完成。以前用數十分鐘都做不完的步驟,而家十分鐘內就可以完成。

Drupal的CKEditor介面使用體驗談

Submitted by saladlam on

用了Drupal的CKEditor介面打文章幾天,發覺了以下影響使用體驗的問題。

  1. 用了本身CKEditor自帶的Image upload功能插入圖像。Upload 50張圖要花二十幾分鐘,重複同一個動作50次。太慢同時對使用者來講太勞累。雖然可以用番傳統的先Upload image後貼URI的方法,但我想利用Drupal來管理檔案。
  2. 想在Image前或後打字,好難控制Cursor去適當位置。
  3. 開了<p>新段落後想反悔,不能直接刪除,要用Source code介面刪除。
  4. Ctrl+Z還原功能,有時得有時唔得。也有時還原得太多,連我想保留的內容都刪除了。
  5. 打Body的地方太細,每次打字要手動拉高才有多些位睇內容。
  6. 試過打好整篇文章後存檔,但Browser連不上Server。所有內容唔見曬,要重新打過。這個是Browser程式的通病。

大部份的問題都不能簡單解決。至於第一點,我睇睇可否寫個模組去解決佢。