CCK create custom non-standard field - drupal

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

Related

bilingual custom field labels with ACF (free version)

I am using custom fields (with the free version of ACF) to add additional, sometimes required, formatted content to the respective custom post type entries. I put together a little site-specific plugin which includes filters to add the custom fields to excerpt and content and puts them out, via a loop, as a list of:
{CUSTOM FIELD LABEL}: {CUSTOM FIELD VALUE}
The website should be available in English and German. Using the Sublanguage plugin, I could translate most of the website, but not the custom field labels.
From what I read on i18n/l10n and Wordpress, I understood that I should best use __() for the labels when creating the custom fields. Since custom field creation is realized by ACF plugin code, I assume I have to create the fields "myself" so that I can do multilingual labels using __(). I guess, I would then realize the actual translation of the fields with Loco Translate.
ACF offers a neat way to export my already existing ACF-created field groups, which provides me with the PHP code to create the fields "on my own". I put the ACF code inside a new function in my site-specific plugin and hooked it to the acf/init action. I did pretty much the same as described in this question, but nothing happens: When I trash the custom field groups within the ACF interface afterwards, no custom fields appear in the "new post" screen.
So basically, I am having one question that, depending on the answer, will spawn follow-up questions:
Is this how I should and can realize bi/multilingual custom field labels?
If no: How else would you implement bilingual custom field labels/names?
If yes: Am I hooking the function to the wrong action?
PS: I wasn't sure if this belongs here or in the WP StackExchange, since part of it is coding related and part of translation-logic-related. Please tell me if I should move it over to the other platform.
Alright,
I was able to solve most of this myself in the meantime:
I did not hook into the correct action. As it turns out, acf/init is only available in ACFv5 (pro), while the free edition is still in version 4.x. I hooked into init - et voilĂ : there are my field groups.
Using __() functions to declare my custom fields' labels, Loco Translate made it quite easy to translate the strings myself.
Conclusion
Apparently, my assumptions were correct - this is how to create internationalized custom field labels :) Nevertheless, I wasn't able to effectively translate the options of a checkbox field I am using, although Loco recognized the string and I provided a translation.
However....
The solution is far from perfect:
I am now using two plugins to translate as much as possible on the website.
Creating the ACF field groups "myself" through PHP code in my site-specific plugin, I needed to remove them from the admin UI. This means, that it's going to be difficult for any standard users to change anything about them in the future (which might of course be a feature as well :))

Drupal 7, Creating widget with ImageField and a Textarea

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.

How to create a custom form in drupal

I need help on how to create a 'custom form' using the same fields provided by cck.
Drupal gives you the ability to add fields to 'nodes' and how to theme their output. But I would like to be able to post a data from my own form (that pops-up) and sends data to the drupal database using the same drupal cck.
How do I access the specific form inputs to add data to my content types ? because the default form is kind of 'ugly' and loads on different page(without ajax).
Help would be much appreciated
There are several routes you could go down.
The easier option is to use the Webforms module. While this gives you similar fields to cck, they are not exactly the same, and if you have a module that implements a specific cck field type, it won't be available to webforms.
The second choice is to write your own module using the forms api. This can mean a lot of learning, add it takes time to get up to speed, but ultimately you have total control over how your form will look and behave. The forms api doesn't give you exactly the same fields, but all the tools are there to create them. Sometimes you need to hack open a module to find out haw a specific field is implemented.
A third option would be to use cck itself. You could create a content type and add the field types you want on your form. You would them give users permission to create but not view or edit the content type. The form submissions would them be nodes on your website. This would make me slightly nervous, so make sure all your permissions are correct!
The second part of your question: you can use a theme file to override the appearance of most forms and make them pretty.
James

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

drupal-----add a field to the content type story

now, i want to add a dead time field(the style is 02-12-2010) to the content type story. how to do that, i used the hook_form_alter() and format_date(),but when i created a new article,and select the time.but the time can't show on the article's page.why?
Why don't try contributed modules instead?
A more elegant solution I think will be using the CCK module which provides the ability of adding new fields to content types (as well as creating new content types), you can install then the Date module provides you with the ability to attach date fields to content types.

Resources