Hi,
I tried to work through the tutorial on how to create new content types (http://drupal.org/node/231019). Some things work while some others do not:
- I see the module in the list and I can enable it (no white screen)
- I can create a new content type using my created module
- The permissions appear, and I can set them
- BUT: When I click on "create content" -> "My Module Content", I see the standard content interface. In the "hook_form", I added two additional fields, but they don't show up in the "create content" view.
Before I loose too much time on this, it would be interesting to know if what I intend to do is technically possible.
!! NOTE !! I am not asking how to do this. I've been doing development for more than ten years. So I should be fine ;) What I do need to know, it if the following is possible in drupal.
What I want to do
I want to dynamically retrieve content from a remote service I created a while ago. I would like to make this service easily available in a couple of drupal installations. So, writing a module seems the right way to go. Essentially, I only need the primary key of the remote content to retrieve it. The most straight-forward scenario would be to save it inside an existing field (like "title" or "body") and let "hook_view" take care of retrieving the data.
This wouldn't be very user-friendly though. So I intend to customize the "create content" form as much as possible. What I intend to achieve is to allow the user to "search" the remote service and pick a content element from a list. All this, using AJAX and some additional custom JavaScript.
I imagine it to be something like this:
The user has a small "search" box. Once the user starts the search, a list of matching items will be displayed below the search box. Preferably a list of DIVs created dynamically as they are nicer than a standard listbox (and I can add images. which would be great).
The user then selects the item and drupal only saves the primary key. Upon "hook_view", the module determines if the content should be fetched, does that, and displays it.
To do this, "hook_form" seems too limited. Unless I've missed something. So, are there ways around this limitation? An all-custom-html form perhaps?
Comments
Yes
Yes, it's quite possible. You might want to study http://drupal.org/project/aef_externodes as an example.
Correct me if I'm wrong but
Correct me if I'm wrong but based on my experience, hook_form_FORM_ID_alter() is superior than hook_form_alter(), by superior I mean it is being read last.
Also, hook_form_alter() are run by their module's name alphabetically. So if your module's name is not in between the module whos hook_form_alter() is being run while displaying the form to Z, then it won't be called.
With that said, it would help if you could us some code.
hook_form_FORM_ID_alter() is
hook_form_FORM_ID_alter() is read before hook_form_alter(), not after:
http://api.drupal.org/api/function/hook_form_FORM_ID_alter/6
Contact me to contract me for D7 -> D10/11 migrations.
Ops sorry, I know somethings
Ops sorry, I know somethings wrong with my comment yesterday. :)
Be warned - dynamic forms and
Be warned - dynamic forms and Drupal are not as simple as adding a bit of javascript to create form elements. For security purposes, Drupal caches the form on the server before serving it to the user, then compares the returned values to the cached form. Any data not in the cached form is discarded. If you want to create dynamic forms in Drupal, you need to use AHAH, which isn't the easiest thing to deal with. The AHAH helper module helps a lot, though it is a little buggy at times, and requires various workarounds.
Contact me to contract me for D7 -> D10/11 migrations.