Nguyen Tien Si

Các hook bắt buộc khi tạo Field type mới cho Drupal (7+)

Trước khi tìm hiểu những hook bắt buộc phải biết một Field type gồm những thành phần nào, theo kiến trúc của Field API thì một Field type gồm 3 thành phần chính:

  1. Đinh nghĩa thông tin cho Field - Phần định nghĩa Field này khai báo thông tin như: Khai báo thông tin cho Field, định nghĩa cấu trúc CSDL cho Field, kiểm tra giá trị hợp lệ, kiểm tra Field rổng hay không.
  2. Định nghĩa Formatter cho Field - Khai báo kiểu hiển thị của Field.
  3. Định nghĩa Widget cho Field - Khai báo phần nhập liệu của Field.

Vậy khi viết một Field type mới cần bắt buộc các hook sau đây:

Ngoài các hook bắt buộc trên còn các hook khác như hook_field_widget_error, hook_field_settings_form,... khi đụng chạm thực tế thì cần tìm hiểu thêm ở những module thực tế.

No comments

Add your comment

The content of this field is kept private and will not be shown publicly. If you have a Gravatar account, used to display your avatar.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options