简体   繁体   English

Drupal模块开发实例

[英]Drupal module development examples

I'm new to Drupal, but I want to create an add-on. 我是Drupal的新手,但我想创建一个附加组件。 The add-on requires some sort of multi-page form with advanced jQuery (I already looked at the jQuery module). 附加组件需要某种带有高级jQuery的多页表单(我已经查看过jQuery模块)。 The add-on requires details of the current logged in user and will also communicate with an external database. 附加组件需要当前登录用户的详细信息,并且还将与外部数据库通信。

I've been looking at tutorials concerning Module creation etc. But they mostly cover creation of simple forms, where as what I want to create is more of a plugin. 我一直在寻找有关模块创建等的教程。但它们主要涵盖简单表单的创建,而我想要创建的更多是插件。

Multi page forms are a total drag. 多页表单是一个完全阻力。 Pro Drupal Development , has a very good section on this topic, and I highly recommend that book if you are doing any Drupal development. Pro Drupal Development ,有关于这个主题的非常好的部分,如果你正在进行任何Drupal开发,我强烈推荐这本书。

Online I found the following article pretty useful too (though I ultimately went with my own system). 在线我发现以下文章也非常有用(尽管我最终使用了我自己的系统)。

http://www.nicklewis.org/using-chaos-tools-form-wizard-build-multistep-forms-drupal-6 http://www.nicklewis.org/using-chaos-tools-form-wizard-build-multistep-forms-drupal-6

There's a decent example here: http://thedrupalblog.com/creating-multipage-form-using-forms-api 这里有一个不错的例子: http//thedrupalblog.com/creating-multipage-form-using-forms-api

To make the most out of this, you're going to want to get pretty friendly with the Form API: http://drupal.org/node/204270 为了充分利用这一点,您将希望使用Form API变得非常友好: http//drupal.org/node/204270

Sadly Drupal.org seems to be missing a Drupal 6.x explanation (though plenty exist for 5.x and 4.7 oddly enough). 可悲的是,Drupal.org似乎错过了Drupal 6.x的解释(尽管5.x和4.7存在很多奇怪的存在)。

Multi step forms are complex by nature, but there are some methods to make it easier. 多步形式本质上是复杂的,但有一些方法可以使它更容易。 I recommend that you have a look at the multistep form tools offered by the Ctools module . 我建议您查看Ctools模块提供的多步骤表单工具。 This blog post by Nick Lewis explains how you can use it. Nick Lewis的这篇博客文章介绍了如何使用它。

I think you should think twice before going with javascript/jQuery to create your forms. 我认为在使用javascript / jQuery创建表单之前你应该三思而后行。 Javascript is a great way to improve the user interface, but it can be easily manipulated because it's client side technology. Javascript是一种改进用户界面的好方法,但它可以很容易地操作,因为它是客户端技术。 You shouldn't rely on javascript alone for things like input validation, temporary storage of form values and controlling the flow between different steps of the form. 你不应该单独依赖javascript来进行输入验证,表单值的临时存储以及控制表单不同步骤之间的流程。

I feel odd saying this, but I don't think you want to use the Drupal Forms API. 我觉得这很奇怪,但我认为你不想使用Drupal Forms API。

The Forms API provides a lot of security features (unique token, rebuilds form after submit to compare to ensure correct form is processed, etc.) and allows other modules to modify your forms, but I think a lot of those features will get in the way of your jEditable form. Forms API提供了许多安全功能(唯一令牌,在提交后重建表单以进行比较以确保处理正确的表单等)并允许其他模块修改您的表单,但我认为很多这些功能都会进入你的jEditable表单的方式。 Multi-page forms are not that challenging using the Forms API, but jEditable elements will be. 多页表单使用Forms API并不具有挑战性,但jEditable元素将是。

Your module could simply add a menu item with a page callback function that puts together your jEditable form for you. 您的模块可以简单地添加一个带有页面回调函数的菜单项,该函数将您的jEditable表单放在一起。 That is about as close to the world of a 'normal PHP' script as Drupal will let you get. 这与Drupal让你得到的“普通PHP”脚本的世界非常接近。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM