WYSIWYG editor in texarea for Drupal configuration form - drupal

Is it possible to use a WYSIWYG editor in texarea
for Drupal site configuration form (system_settings_form).
This is how the configuration is coded now...
$form['my_module_text_bottom'] = array(
'#type' => 'textarea',
'#title' => t('Some text'),
'#default_value' => variable_get('my_module_text_bottom', 'This is configurable text found in the module configuration.'),
'#size' => 1024,
'#maxlength' => 1024,
'#description' => t("Some text."),
'#required' => TRUE,
);
return system_settings_form($form);

Here it is for Drupal 7 and Drupal 6.
For D7:
<?php
// Retrieve the default values for 'value' and 'format', if not readily
// available through other means:
$defaults = array(
'value' => '',
'format' => filter_default_format(),
);
$my_richtext_field = variable_get('my_richtext_field', $defaults);
// Just construct a regular #type 'text_format' form element:
$form['my_richtext_field'] = array(
'#type' => 'text_format',
'#title' => t('My richtext field'),
'#default_value' => $my_richtext_field['value'],
'#format' => $my_richtext_field['format'],
);
?>
For D6:
<?php
// Your saved or new data is supposed to have a value and a format. Just like
// $node has a $node->body and $node->format. May also come from a
// variable_get('mymodule_admin_setting', array('value' => '', 'format' => NULL));
$mydata = mymodule_data_load();
$form['myfield']['mytextarea'] = array(
'#type' => 'textarea',
'#title' => t('My textarea'),
'#default_value' => $mydata->value,
);
$form['myfield']['format'] = filter_form($mydata->format);
?>

I kept searching for this issue for about 6 hours and finally i found the reason, for your custom textarea field you must add this line, to use the default input format (Full HTML):
$form['format'] = filter_form();
be careful if you use this form element inside fieldset you must include this fieldset:
$form['donation-instructions']['format'] = filter_form();
I hope this will help you

The WYSIWYG or CKEditor modules should be able to do this.

I found this question similar to:
Drupal 6: Implement Wysiwyg on Custom Module Form
One of the answers there pointed to this drupal.org page:
http://drupal.org/node/358316
which provides fairly detailed examples of the "format" array key and filter_form(), also describing how it's used if your form has multiple textareas.
The approach given there doesn't apply to Drupal 7.
I ran into a similar situation where I'd downloaded and installed and installed CKEditor and it displayed when editing content nodes, but didn't display for the textarea on a configuration form for my module.

Related

ACF Custom fields, and Wordpress Timber front end forms

I'm trying to create a custom form on the front end so that logged in visitors can post their own content.
Using ACF pro and Timber.
In my page.php file I have
$new_post = array(
'post_id' => 'new_post',
'post_title' => true,
'post_content' => true,
'field_groups' => array(26), // Create post field group ID(s)
'form' => true,
'return' => '%post_url%', // Redirect to new post url
'html_before_fields' => '<div class="foobar">',
'html_after_fields' => '</div>',
'new_post' => array(
'post_status' => 'draft',
'post_type' => 'vlog'
),
'submit_value' => 'Create Post'
);
$context['vlogform'] = acf_form($new_post);
and in page.twig, I have placed
{{vlogform}}
The form renders - but its stuck in a silly place, not where I want it. Its stuck above the html element...
Any pointers?
Thanks,
Rob
** Edit **
This doesn't work
$context['vf_form'] = Timber\Helper::ob_function('acf_form', $new_post);
but this does...
ob_start();
acf_Form($new_post);
$context['vf_form'] = ob_get_clean();
Materially, what is the difference?
Thanks,
Rob
This might be a little late, but I've managed to fix this issue by using an argument that they have added recently. I found this googling for it, so for future seekers this might come in handy.
So, in the args array, add the following:
$args = array(
'echo' => false,
);
So as other answers have mentioned acf_form() outputs the form when it is called.
To prevent the form from rendering at the top of the document, pass over your form arguments from the controller (page.php) to the view
acf_form_head();
get_header();
$context = Timber::context();
$context['post'] = new TimberPost();
$context['form_args'] = [
'post_id' => 'new_post',
'post_title' => true,
'post_content' => true,
'field_groups' => [26], // Create post field group ID(s)
'form' => true,
'return' => '%post_url%', // Redirect to new post url
'html_before_fields' => '<div class="foobar">',
'html_after_fields' => '</div>',
'new_post' => [
'post_status' => 'draft',
'post_type' => 'vlog'
],
'submit_value' => 'Create Post'
];
Timber::render('example-view.twig', $context);
get_footer();
Then in your view, use timbers function()helper method to call acf_form()
{{ function('acf_form', form_args) }}
src: https://timber.github.io/docs/guides/functions/#function
I am using latest Timber (via composer) and ACF Pro 5.9.1
On older versions of Timber, I took advantage of a similar helper method (TimberHelper::function) in the controller which is now deprecated
The problem is that acf_form is also echoing when called in the PHP file. You can either look for an alternate function (is there something like get_acf_form that returns the HTML but doesn't echo?) OR use Timber's output buffer wrapper:
$contect['vf_form'] = Timber\Helper::ob_function('acf_form', $new_post);
... this will store the data in the vf_form attribute, but not suppress it from echoing until called in Twig

managed_file form element doesn't render correctly

I have a simple managed file form element that is the only element in my form. It looks like this:
$form['upload'] = array(
'#type' => 'managed_file',
'#title' => t('Select a YML file'),
'#progress_message' => t('Please wait...'),
'#progress_indicator' => 'bar',
'#description' => t('Click "Browse..." to select a file to upload.'),
'#required' => TRUE,
'#upload_validators' => array('file_validate_extensions' => array('yml txt docx')),
'#upload_location' => $upload_dest,
);
When I render the form using the drupal_get_form callback in hook_menu I get a perfectly formed managed_file upload field with the browse and upload buttons. Things change when I decide I want to add a table of information underneath the form. This requires building a table using theme functions then adding that to the form by rendering the form and appending the table. I create my table and add it to the form:
$rows = array();
foreach($yml_files as $yml_file){
$rows[] = array($yml_file->uri, $yml_file->filename);
}
$output = drupal_render($form['upload']);
$output .= theme('table', array('header'=>$header, 'rows'=>$rows));
return $output;
When I generate the form using drupal_render, I get the nice help text, but no upload form. The table renders fine in both scenarios and I'm not seeing any errors.
If Drupal uses drupal_render to render its forms why would the form look different in the second scnenario? Is there a way to get the entire form? I've tried a variety of ways of passing the form and using dpm to print the form at various stages and I'm not sure where to go from here.
Standard file upload fields render correctly as do other form elements. It seems to be limited to the managed_file element.
When using a drupal_get_form menu callback, you should return your $form array and not an already rendered themeable array. Probably you are missing #attached js files for the managed_file field.
What you could do in your case is to add the table output on a markup field of your form.
$form['upload'] = array(
'#type' => 'managed_file',
'#title' => t('Select a YML file'),
'#progress_message' => t('Please wait...'),
'#progress_indicator' => 'bar',
'#description' => t('Click "Browse..." to select a file to upload.'),
'#required' => TRUE,
'#upload_validators' => array('file_validate_extensions' => array('yml txt docx')),
'#upload_location' => $upload_dest,
);
$form['table'] = array(
'#markup' => theme('table', array('header' => $header, 'rows' => $rows)),
);
return $form;

Creating custom options for "List-item" option in Option Tree plugin for wordpress

I have a problem, I need to change the default options for a “List-item” option in Option tree . Right now the default are “Title/Image/Link/Descriptions” .. I want to remove them and add my own. I have written this code:
array(
'id' => 'academic_success_content',
'label' => 'Academic Success Content',
'desc' => 'Enter the academic success content. It will appear in the home page in list items format',
'std' => '',
'type' => 'list-item',
'section' => 'academic_perfomance',
'settings' => array(
array(
'id' => 'academic_success',
'label' => 'Academic Success',
'type' => 'textarea-simple',
)
)
),
But when I preview the themes options , the default list item "title" is still there and I only want to see the Academic Success textarea. What should I do?
I also suffered from the same situation.
And after that, I use the older version of "list-item" and "gallery".
This has worked well. Ex: v2.4.6
Is the theme options page being included?
You'll need to reference it in your functions.php, something to the effect of:
require_once locate_template('/path-to-your/theme-options.php' );

Video Module with Drupal 7 custom form

How can I use video module drupal 7 version with Custom form to create a field behave exactly the field on the node form? To do so I created a form with video field type but its not displaying anything
$form['file'] = array(
'#type' => 'video',
'#name' => 'files[]',
'#title' => t('Upload some videos'),
'#attributes' => array('multiple' => 'multiple'),
);
I used this From the test file of video.The filename is. VideoField.test

How to add content to user profile page in Drupal 7?

I'm trying to add a couple of sections onto the user profile in Drupal 7 under:
<div class="profile" typeof="sioc:UserAccount" about="/drupal/user/1">
I'm adding three new sections, but the problem is that, although I am using the same way to add the three sections, only one of them is rendered as a child of the div above, while the other two are rendered as siblings. What am I doing wrong?
This is how I'm creating the content:
function plan_user_user_view($account) {
//Create the markup for the events region
$account->content['events'] = array(
'#type' => 'user_profile_item',
'#theme' => 'events',
'#events' => $events);
//Create the region for the venues
$account->content['venues'] = array(
'#type' => 'user_profile_item',
'#theme' =>'venues',
'#userid' => $user->uid,
'#venues' => $venues);
//Create the region for creating an event
$account->content['creator'] = array(
'#prefix' => '<div class="user-event-item" id="quick-event-creator">',
'#suffix' => '</div>',
'#type' => 'user_profile_item',
'#title' => t('QUICK EVENT CREATOR'),
'#markup' => drupal_render(drupal_get_form('event_creation')));
}
Also, is there a better way to create that last piece of content there? The other two seem fine in a template file but the last one since it's a form I was wondering if there are better ways of doing that.
Thanks,
Maybe you should have a look on this project profil2 which is the successor of content_profil for Drupal 6. With it you will be able to add informations onto users profils and if you want to code your custom fields by yourself it should be a good starting point to read.
Best.
How about this:
// Create the category.
$account->content['mymodule'] = array(
'#type' => 'user_profile_category',
'#title' => t('My module content'),
);
// Create first item (child).
$account->content['mymodule']['events'] = array(
'#type' => 'user_profile_item',
'#title' => t('Events'),
'#markup' => t('Whatever'),
);
// Create second item (child).
$account->content['mymodule']['venues'] = array(
'#type' => 'user_profile_item',
'#title' => t('Venues'),
'#markup' => t('Whatever'),
);
and so on. The bottom line is that user_profile_item items should be children of a user_profile_category item.

Resources