SlideShare a Scribd company logo
CCK 欄位模組開發簡介
為何要開發 CCK 欄位模組

 目前的 CCK 欄位模組沒有適合的應用
 需要使用 Form API 修改的地方太多
 透過 Form API 無法改出需要的效果
   hook_form_alter
   欄位預設值使用 PHP Code
   #pre_render、#process、#after_build
 需要同時儲存好幾個資料庫的欄位
 編輯或呈現方式跟現有的欄位模組不同
 根據其他欄位的值做運算
開發 CCK 欄位模組的替代方案

 使用前提
    如果只使用在一個特定的內容類型上
    修改地方不多
    無需呈現特殊的 widget
 Computed Field
    可以儲存資料
    在 Views 中可以依欄位內容做排序、過濾
    下載:http://drupal.org/project/computed_field 
    小抄:http://drupal.org/node/149228
 Dynamic Field
    不可儲存資料
    下載:http://drupal.org/project/dynamicfield
勾點函數

xxx_info:CCK 欄位設定畫面的說明
   Manage fields



   Display fields


hook_field_info
勾點函數

hook_widget_info




 hook_field_formatter_info
hook_field_info 相關的勾點函數

 hook_field_settings($op, $field)
    定義欄位設定表單、資料庫欄位及其操作(例如:form、
    save、database columns)
    只需儲存一個欄位的資料時,將欄位名稱設成 'value'
    這裡所說的儲存欄位並非欄位設定表單上的欄位,而是此
    CCK 欄位所要儲存的資料欄位
hook_field_info 相關的勾點函數

 hook_field($op, &$node, $field, &$items, $teaser, $page)
   定義各種欄位操作(例如:insert、update)
   若 hook_field_settings 沒有定義任何的資料庫欄位,將不會
   觸發 insert、update 的操作

 hook_content_is_empty($item, $field)
    測試欄位內容是否為空
hook_widget_info 相關的勾點函數

 hook_widget(&$form, &$form_state, $field, $items, $delta =
 0)
    輸出變數的結構會影響其他勾點函數的操作
      '#tree' => false 用 return $element;
      '#tree' => true 用 return array($element);
hook_field_formatter_info 相關的勾點函
數
 hook_theme
    'hook_formatter_XXX' 會對應到 hook_field_formatter_info
    的 XXX 項目
hook_field_formatter_info 相關的勾點函
數
 theme_hook_formatter_default($element)
    需對預覽狀況做處理('#tree' = true 的狀況)
勾點函數執行順序(insert node)

 1.   widget prepare form values
 2.   widget form
 3.   widget validate
 4.   widget process form values
 5.   field validate
 6.   content_field validate
 7.   widget submit
 8.   widget process form values
 9.   field submit
10.   content_field submit
11.   field insert
12.   content_field insert
勾點函數執行順序(update node)

 1.   widget prepare form values
 2.   widget form
 3.   widget validate
 4.   widget process form values
 5.   field validate
 6.   content_field validate
 7.   widget submit
 8.   widget process form values
 9.   field submit
10.   content_field submit
11.   field update
12.   content_field update
勾點函數執行順序(preview node)

1.   widget prepare form values
2.   widget form
3.   widget validate
4.   widget process form values
5.   field validate
6.   content_field validate
7.   widget process form values
8.   field view
參考模組

CCK:
  http://drupal.org/project/cck
  有最基本的寫法可以參考

Fivestar:
   http://drupal.org/project/fivestar
   各種的對應方式(約 80%)都可以在這個模組中學習到
參考資料

Pro Drupal Development:
   http://www.amazon.com/o/ASIN/1430209895
CCK Module Basics:
   http://learnbythedrop.com/drop/86
Creating Custom CCK Fields
   http://www.lullabot.com/articles/creating-custom-cck-
   fields
CCK for developers
   http://drupal.org/node/101742
CCK Documentation Resources
   http://api.audean.com

More Related Content

KEY
phpconf 2012 yii
PPT
通行证项目技术分享
PPTX
設計模式.搭架電子發票框架
PDF
[DCTPE2011] 8) 多伺服器/高效能的Drupal 主機解決方案--黃雋
PDF
[DCTPE2011] 3) 主題演講:用Drupal 打造更美好的網際網路
PDF
[DCTPE2011] Drupal 6 的 CCK/Views運用--黎偉志
PDF
[DCTPE2010] Drupal & (Open/Anti) Government
PPT
[DCTPE2010] Drupal 遇上行動網路服務
phpconf 2012 yii
通行证项目技术分享
設計模式.搭架電子發票框架
[DCTPE2011] 8) 多伺服器/高效能的Drupal 主機解決方案--黃雋
[DCTPE2011] 3) 主題演講:用Drupal 打造更美好的網際網路
[DCTPE2011] Drupal 6 的 CCK/Views運用--黎偉志
[DCTPE2010] Drupal & (Open/Anti) Government
[DCTPE2010] Drupal 遇上行動網路服務

Viewers also liked (20)

PDF
[DCTPE2011] 11) Drupal 是好的生財工具嗎? 2. 中小型網站製作公司/工作室座談
PDF
[DCTPE2010] Drupal 與網路的未來趨勢
PPT
[DCTPE2010] 開場:Drupal與Drupal台灣
PDF
[DCTPE2011] 11) Drupal 是好的生財工具嗎? 1. 網站標案經驗分享 x 2
PPT
[DCTPE2010] 從企劃到開發維護的 Drupal 專案經驗
PPT
[DCTPE2011] Drupal 7 的Fields/Views 運用
PDF
[DCTPE2010] Open Hopen 政府網站的理想與現實
PDF
[DCTPE2011] Drupal 6 的 CCK/Views運用--林振昇
PDF
[DCTPE2010] Biodiversity & Drupal
PPT
[DCTPE2010] Drupal 學術應用-申請入學網路單一窗口
PPTX
[DCTPE2010] Drupalcamp 商業案例:獎金獵人 share
PDF
[DCTPE2011] 8) 多伺服器/高效能的Drupal 主機解決方案--James Liu
PDF
[DCTPE2011] 10) Drupal與Facebook交朋友
PDF
[DCTPE2011] 5) 用 Drupal 打造美好資訊架構(英/中雙語)
PDF
[DCTPE2011] 7) Mobile Drupal(英/中雙語)
PPT
[DCTPE2010] 多站架設商業應用與實務-以本土癮科技為例
PDF
[DCTPE2010] Microsoft
PDF
[DCTPE2011] 9) 案例分析 1. NNCF.org - Content, Commerce, CRM
PDF
[DCTPE2010] Drupal 模組開發入門
PDF
[DCTPE2011]Drupalthon intro
[DCTPE2011] 11) Drupal 是好的生財工具嗎? 2. 中小型網站製作公司/工作室座談
[DCTPE2010] Drupal 與網路的未來趨勢
[DCTPE2010] 開場:Drupal與Drupal台灣
[DCTPE2011] 11) Drupal 是好的生財工具嗎? 1. 網站標案經驗分享 x 2
[DCTPE2010] 從企劃到開發維護的 Drupal 專案經驗
[DCTPE2011] Drupal 7 的Fields/Views 運用
[DCTPE2010] Open Hopen 政府網站的理想與現實
[DCTPE2011] Drupal 6 的 CCK/Views運用--林振昇
[DCTPE2010] Biodiversity & Drupal
[DCTPE2010] Drupal 學術應用-申請入學網路單一窗口
[DCTPE2010] Drupalcamp 商業案例:獎金獵人 share
[DCTPE2011] 8) 多伺服器/高效能的Drupal 主機解決方案--James Liu
[DCTPE2011] 10) Drupal與Facebook交朋友
[DCTPE2011] 5) 用 Drupal 打造美好資訊架構(英/中雙語)
[DCTPE2011] 7) Mobile Drupal(英/中雙語)
[DCTPE2010] 多站架設商業應用與實務-以本土癮科技為例
[DCTPE2010] Microsoft
[DCTPE2011] 9) 案例分析 1. NNCF.org - Content, Commerce, CRM
[DCTPE2010] Drupal 模組開發入門
[DCTPE2011]Drupalthon intro
Ad

Similar to [DCTPE2010] 如何開發 CCK 欄位模組 (20)

PDF
Asp.net mvc網站的從無到有
PDF
twMVC#04 | ASP.NET MVC 4 新功能介紹(快速上手)
PDF
ASP.NET MVC 4 新功能介紹(快速上手) -twMVC#4
PDF
Asp.Net Mvc 1.0
PDF
ASP.NET Core MVC 2.2從開發到測試 - Development & Unit Testing
PPTX
twMVC#01 | ASP.NET MVC 的第一次親密接觸
PDF
Real World ASP.NET MVC
PPTX
Uliweb设计分享
PPSX
利用 ASP.NET MVC 提升您的 Web 應用程式
PPTX
Introduction to ASP.NET MVC and MVC 5 Features
PPTX
2015 年逢甲大學資訊系:ASP.NET MVC 4 教育訓練3
PDF
ASP.NET Core 2.1設計新思維與新發展
PPTX
使用 ASP.NET 5 實戰開發雲端應用程式
PDF
Spring 2.x 中文
PDF
Supersonic Subatomic Quarkus accelerate cloud native development
PDF
全栈三个月开发绩效系统 using Rails 7.1 to develop people performance evaluation system
PDF
I os 16
PDF
與 Asp.net mvc 的第一次親密接觸 - twMVC#1
PPTX
ASP.Net MVC Framework
PPTX
使用 TypeScript 駕馭 Web 世界的脫韁野馬:以 Angular 2 開發框架為例
Asp.net mvc網站的從無到有
twMVC#04 | ASP.NET MVC 4 新功能介紹(快速上手)
ASP.NET MVC 4 新功能介紹(快速上手) -twMVC#4
Asp.Net Mvc 1.0
ASP.NET Core MVC 2.2從開發到測試 - Development & Unit Testing
twMVC#01 | ASP.NET MVC 的第一次親密接觸
Real World ASP.NET MVC
Uliweb设计分享
利用 ASP.NET MVC 提升您的 Web 應用程式
Introduction to ASP.NET MVC and MVC 5 Features
2015 年逢甲大學資訊系:ASP.NET MVC 4 教育訓練3
ASP.NET Core 2.1設計新思維與新發展
使用 ASP.NET 5 實戰開發雲端應用程式
Spring 2.x 中文
Supersonic Subatomic Quarkus accelerate cloud native development
全栈三个月开发绩效系统 using Rails 7.1 to develop people performance evaluation system
I os 16
與 Asp.net mvc 的第一次親密接觸 - twMVC#1
ASP.Net MVC Framework
使用 TypeScript 駕馭 Web 世界的脫韁野馬:以 Angular 2 開發框架為例
Ad

[DCTPE2010] 如何開發 CCK 欄位模組