Drupal 7, Creating widget with ImageField and a Textarea - drupal

Can anyone help me figure out how can i create a widget(Field API) which will contain an image(i want to to be an ImageField) and a textarea in Drupal 7?
Unfortunately i cannot find any tutorial how to do this on google.
Thanks!

There's no tutorial as such that I know of, but have a look at the Drupal Examples Module, there's a module within called field_example with all of the info you need.
On a very basic level you want to do this:
Implement hook_field_schema() in your module's .install file to define what columns are going to be held in your field table (probably file ID (fid), alternative text for the image, title text for the image and the contents of the text area in your case).
Implement hook_field_info() to define your field type.
Implement hook_field_is_empty() to provide a way for Drupal to know that a particular instance of a field is empty and can be removed when the entity is saved.
Implement hook_field_formatter_info() to tell Drupal the different ways the content of your field can be displayed.
Implement hook_field_formatter_view to define exactly how those field formatters defined in step 4 will be outputted.
Implement hook_field_widget_info to define the different input widgets for your field.
Implement hook_field_widget_form to define the elements that will make up the widget for your field.
Once you've jumped through all of those hoops (it doesn't actually take that long to implement, most functions are just a few lines of code), enable the module and start adding your new field to entities!

you should start from this 2 hook to create the widget.
then you should start creating the compound field
hook_field_widget_info()
hook_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element)
here are some link to create custom field and widget
http://www.phase2technology.com/node/1495/
http://drupal.org/project/dnd_character

Sorry for not closing this. but the real answer to this is to use Field Collection module - drupal.org/project/field_collection. You add multiple field to this. When i asked this question i was new to D7 and in D6 we had to write this by hand. great module!

Try taking a look at this tutorial. Most other ones the writer concentrates on sounding clever, this one has screenshots and is very clear and concise.

Related

Add custom form data to Drupal module without using CCK fields

Iam very new to Drupal 7 so bear with me. I have created a jQueryUI drag and drop interface with JQueryUI tabs. My problem is i cant find the correct hook to add this custom interface to the admin interface. Like so (mockup) http://onlinemedia.rmcad.edu/sandBox/screenshot/screen-shot.jpg
All the examples I find are using CCK fields. CCK fields are great but they dont have this kind of custom functionality I want or does it?
Any help would very much be appreciated.
J
cck is drupal 6, not 7. to add to the node creation form you could use hook_form_alter or hook_form_ID_alter.
Check the form api documentation to get an idea of how to add stuff to the form object in either of those hooks.
From your mockup I understand you intend to add this drag&drop interface to a content-type.
If that's the case, I'd recommend you to add the appropriate fields first. Those would help storing the data in Drupal way, once the node is saved.
Once you are satisfied with the fields collecting the data you need, create a module and use hook_form_FORM_ID_alter hook to integrate your "interface", the presentation layer by altering those fields.
If you don't want to add CCK/Field components to store your data how about you create your own database table and store your custom data in there?
This approach is a long one but I have used it to great effect on a very big and complex project.
You will need a custom module with an install script which contains the details of your custom database table.
Forgive me but I don't remember the hook for altering a node-edit-form but that is where you input the code which implement your drag-'n'-drop elements.
Then, you could save the settings altogether when the node-edit form is submitted but I think it's probably better to implement some AJAX to save the settings to your custom database table. So, when a component is dropped into it's final resting place, you use AJAX to save that information to the database.
When a user comes back to edit that page, you simply load your custom settings and apply them to the drag-'n'-drop features and their previous configuration(s) would be visible to them.
I do hope that makes sense and it helps you.

CCK create custom non-standard field

I've created new content type. And I want add new custom non-standard field. The field should consist of two text fields. Let's say: double text field. Ex.: Product content type and I want to add features of product such as: weight, length etc(many features). First field is 'Feature' and the second one is 'Value of feature'. The question is: How I can realize such a field? Module, hooks?
You can create your own field pretty easily, you'll need a custom module and to implement a bunch of hooks like you suggest.
Rather than go through all of those here you'd be better off downloading the Examples module, and looking at field_example. I've based tons of custom fields off of that code and they've all worked perfectly. Plus the module is well commented and gives you good insight in to the way the field/widget systems work.
Hope that helps
One straightforward alternative is to use the Field Collection module

drupal replacing default nodes with views page

I have created a page view using field style to display a list of teasers as I want. fields configuration in views allows us to link the field to it's node. but what if we have created view for node detail page and want field to link to it's relevant view.
I had the same question, and after a bit of research this is what I've concluded:
The views module isn't intended to replace a default node view. I say this because of the level of difficulty involved in doing this and the lack of information on how to accomplish this. Ryan Weal has posted a way to accomplish this by editing your node template that doesn't look too difficult to accomplish, and here is the link.
However, it seems that a more popular solution, especially if you are like me and don't like to get into editing theme files. You can use the Display Suite module to effectively reformat the default node content as you would like.
I'm not sure if I understand you properly, but it sounds like you are wanting to display a view in a page view of a node?
In order to do this, you could:
create a small module, using hook_nodeapi() or one of the D7 replacements for this function in order to insert the output of the embedded view into this page's content, by conditionally adding a $content element when the node is of the appropriate id
or (easier, but requires allowing input type PHP) embed the view right on the page.
http://thedrupalblog.com/embedding-view-drupal-6-using-views-embed-view for information on embedding views

How can I show a certain type of contents on a specified page with Drupal 7

When I create a content type, I want to show all the posts of this content type on a page, I have to use view module. I don't like that.
Can I just specify the page and url when I create the content type?
But there is only one option, only front page. Can I change that? Hope you guys can tell me.
The views module is one of Drupal's killer features, you might want to reconsider writing it off completely.
Anyways, if you want to display all nodes of a type, you will have to code this yourself in a custom module. This means you will have to write some SQL, load the nodes and render them in a list. In this example you could use the EntityFieldQuery class to construct the query instead of writing the SQL yourself.
The end result will not be much different than what views will do for you, only difference is that you will need to create all of this with code in a module, instead of just setting this up in the Views UI.
I agree that views is a powerful tool that you shouldn't count out, but if you're set against using it (i refuse to use it on 2 of my sites purely due to overhead), You could use taxonomy instead. The taxonomy module already has a views style list for each term, I used this to achieve something similar to what you're looking for:
Set up a vocabulary whose terms match your node types and note the vid
add a hook_node_insert into your module file:
mymodulename_node_insert($node){
$terms=taxonomy_get_tree($my_vid); //where $my_vid == the vid of your vocabulary.
foreach($terms as $term){
if(strtolower($node->type)==strtolower($term->name)){
$items=array((array)$term);
$field['storage']['type']='field_sql_storage';
taxonomy_field_insert('node', $node, $field, null, null, $items);
}
}
}
After that you just need to add menu links pointing to your taxonomy page. Just as a note, I render all of my lists that I don't use views for with my own custom functions so I'm not sure what limitations this method might present.

drupal translate module issue, assign custom fields to autotranslate

Drupal:Can I assign custom fields to autotranslate them when I create a new article?
By default it creates and translates the Title and Body field, but I have several more depending on the content types. (This is set on actions)
I didn't quite know how to add more fields to translate
I am not exactly sure what those other fields are. Would the be something that is created using CCK or views?
Drupal uses the function t(...) to translate strings, if you want that functionality you need to wrap your text in that.
More info about t() and how it works. (Drupal 6)
More info about the Localization API (PDF cheat sheet)
UPDATE
Just found a link to what might be more suitable for your needs:
Drupal.org > Translating Content in Drupal

Resources