http://www.photouploads.com/images/customfiel.jpg
i have configure a taxonomy as field of a content type, but i want to replace the checkbox label(work with iphone) to an image which is a image field of that taxonomy(see the photo).
At now i only know to alter node.pages.inc at row 290 by add the code:
$form['product_label'] = array(
'#type' => 'checkboxes',
'#title' => 'Checkboxes Title',
'#title_display' => 'before',
'#default_value' => array(0,2),
'#options' => array(
0 => 'option one',
1 => 'option two',
2 => 'option three',
),
'#theme' => 'testmodule_checkboxes',
);
the product_label is the checkbox name, the above code is to override the current checkbox field. But i think this a not a best way to do..
anyone can provide direction to me? what module or coding can do it?
You shouldn't hack core (except in very few edge cases if you really know what you're doing).
The best place to do this is in your theme. In template.php, you need to use the hook, hook_form_alter() to alter that specific form. You can find out more about the FAPI (form API) here and here.
There's a few ways to alter the form to get the result you want. The easiest way would be to add a unique class for each icon to each form item's attributes array. You can then use CSS to replace the text with the icon (this makes it more accessible as screen readers will still be able to read the text).
Related
I'm using KnpLabs/DoctrineBehaviors/Translatable and A2LiX Translation Form to translate my entities in a Symfony application. It works very well. However, when the form is rendered there is a "translations" title that I would like to delete and a "EN [Default]" text on a tab that I would like to change.
In the examples of the doc, there's a "medias" example so I imagine that we can change this text. Moreover, the tabs don't have this [Default] text. So I imagine that's possible to change them.
And this is mine:
Does anybody know how to do it? If we take a look on the form type options we don't see anything concerning the "Translations" label. For the "Default", I can't see where I should search for it.
Default template file is located at vendor/a2lix/translation-form-bundle/A2lix/TranslationFormBundle/Resources/views/default.html.twig. If you want you can specify your own template and set it in config.yml file, like this:
a2lix_translation_form:
....
templating: "#SLCore/includes/translation.html.twig"
More information can be found here.
For the "translations" title, I was able to override it adding a label to the form type just like a normal field. However, it is not possible to use a blank value. I had to use ' ' in order to override the text.
->add('translations', 'a2lix_translations', array(
'label' => ' ', --> this overrides the translations title
'fields' => array(
'name' => array(
'field_type' => 'text',
'label' => 'blabla'
),
'description' => array(
'field_type' => 'textarea',
'label' => 'bleble',
)
)
))
For the "Default" label, I still have no solution.
I've downloaded the Redux Framework (using generator). I want some fields to be displayed if a checkbox field is checked (more related fields below checkbox).
I searched online and found some Redux code having checkbox_hide_below field which is not present in the current Redux Framework.
Will I have to do it all by myself or Redux framework provides some option to show/hide fields?
Lead dev of Redux here.
You'd have to do it yourself, however it's really pretty easy.
First, you'd do a get_option to your opt_name before you run your config. Then on the fields you want to make hidden you'd do something like this:
$options = get_options('OPT_NAME');
$field = array(
'id' => 'textarea_id',
'type' => 'textarea',
'hidden' => ( $options['test_value'] == 1 ) ? true : false,
'title' => __( 'Test Hidden Field', 'redux-framework-demo' ),
'desc' => __( 'This field will be set to be hidden if text_value is 1.', 'redux-framework-demo' ),
);
It's pretty strait forward. I hope that helps! You can also apply the hidden argument to sections as well. ;)
I'm writing a plugin which creates a custom post_type called "dictionary_entry" which has several custom meta boxes and fields. I'd like to add an addition field which allows the custom post author to upload an audio clip.
I've done some digging and tried the code offered here but I can't get it to work.
I think one possible answer to my question would be the "type" parameter for fields. I've seen "text", "textarea", "time", "color", "radio", etc. but I haven't been able to find a list of all the possibilities. Is it wishful thinking that there might be a field type: "file" or "upload"?
I'm going to skip the code for adding the custom post_type, but here's an example of my code for adding the meta boxes (in case somebody else is trying to use this, remember to use your custom post_type in the 'pages' parameter):
//meta box code
$meta_boxes = array();
$meta_boxes[] = array(
'id' => 'examples', // meta box id, unique per meta box
'title' => 'Examples', // meta box title
'pages' => array('dictionary_entry'), // post types, accept custom post types as well, default is array('post'); optional
'context' => 'normal', // where the meta box appear: normal (default), advanced, side; optional
'priority' => 'high', // order of meta box: high (default), low; optional
'fields' => array( // list of meta fields
array(
'name' => 'Example 1', // field name
'desc' => 'Use it in a sentence? EX: Kanien\'kéha kahrónkha.', // field description, optional
'id' => $prefix . 'example1', // field id, i.e. the meta key
'type' => 'text', // text box
'std' => '', // default value, optional
'validate_func' => 'check_apos' // validate function, created below, inside RW_Meta_Box_Validate class
),
array(
'name' => 'Translation 1', // field name
'desc' => 'What does the sentence mean? EX: I speak Mohawk.', // field description, optional
'id' => $prefix . 'ex_translation1', // field id, i.e. the meta key
'type' => 'text', // text box
'std' => '', // default value, optional
'validate_func' => 'check_apos' // validate function, created below, inside RW_Meta_Box_Validate class
)
)
);
foreach ($meta_boxes as $metabox) {
add_meta_box... //see the codex for add_meta_box()
}
I figured out how to do this by digging into the code found here. If you take a look, you'll recognize parts of my code quoted above. I was originally using this class, but didn't fully realize it. It's a custom class which can be called to add various meta boxes / fields.
It turns out that the "type" parameter I was wondering about actually belongs to this Class (as opposed to the Wordpress API) and that it does allow for a type: 'file' which brings up a default file picker window (not the built-in media uploader). For my purposes this is okay, because I don't need all the slick options.
If you're reading this, you've probably already googled this question and seen a wide variety of posts that partially explain how to do this. For what it's worth, I found this to be the easiest way to add this functionality that ALSO works for custom post_types (without a fair amount of hacking). I hope this is useful to someone else.
In Drupal 7 I created an entity programmatically. It has a few textfields added like name, price etc in the form:
$form['data']['name'] = array(
'#type' => 'textfield',
'#title' => t('Name'),
'#default_value' => isset($model->data['name']) ? $model->data['name']: '',
'#maxlength' => 255,
'#required' => TRUE,
'#weight' => -3,
);
However, I'd like to be able to add multiple images to every entity it as well.
When I use Drupal's user interface to add fields, I can pick "Image: field_image (Image)" at the bottom, under "Add an existing field". This field has exactly the behaviour I want.
How can I add it programmatically to my entity?
You can just extend the content-type you made with the Drupal UI by using the HOOK_form_alter()-hook.
Or you can find out what the Array is generating when you make a multiple image-field by using a var_dump(); and add it to the Array of your custom made template.
I am trying to create a form with the Drupal 5 form API that has two textareas, both of which should have have a wysiwyg editor enabled to allow HTML formatted input. However, only the second textarea has the editor enabled, the other one displays the "Input format selector", but not the editor controls. I have tried this with TinyMCE 3.3.9.3 and 3.3.9.4b and CKEditor 3.5.1.6398 both using the wysiwyg module integration, the result in both cases is the same.
In this related question it is mentioned that there might be a problem of identical IDs. I have no clue how to transfer this solution to the Drupal Form API, since I gave the two fields different names. In the generated HTML, they have separate HTML ids based on the Drupal names I assigned.
The code I used to create the text areas is the following:
$form['oos'] = array(
'#tree' => false,
);
$form['oos']['oosmessage'] = array(
'#description' => t('Something'),
'#title' => t('Generic out of stock message'),
'#type' => 'textarea',
);
$form['oos']['format'] = filter_form(1, 20, array('format'));
$form['oosmd'] = array(
'#tree' => false,
);
$form['oosmd']['oosmessage_date'] = array(
'#type' => 'textarea',
'#title' => t('Out of stock message until a specific date'),
'#description' =>t('Something else.'),
);
$form['oosmd']['format'] = filter_form(1, 20, array('format'));
Thanks!
Ellen
Try to give the two textareas different ids and see if that works.