strumento di formattazione testo (in un campo textarea)

2 contenuti / 0 new
Ultimo contenuto
strumento di formattazione testo (in un campo textarea)

<?php
 form
['gruppo3']['Testo'] = array(
    
'#title' => t('Testo'),
    
'#type' => 'textarea,
     '
#required' => TRUE,
  
);
 
?>

in questa text area posso inserire gli strumenti di formattazione del testo????

se si come????

Il type sarà text_format con #format impostato al formato voluto:

<?php
 $form
['foo']['bar'] = array(
   
'#type'     => 'text_format',
   
'#title'    => 'Bar',
   
'#definition' => 'Foo Bar',
   
'#default_value' => variable_get('bar', ''),
   
'#weight'   => 1,
   
'#format' => 'filtered_html',
   
'#required' => FALSE,
  );
?>

In assenza di una release stabile di Better module per i formati, è possibile creare un modulo personalizzato per fare questo per specifici tipi o campi contenuto.

<?php
/**
* Implements hook_element_info_alter().
*
* Sets the text format processor to a custom callback function.
* This code is taken from the Better Formats module.
*/
function default_text_format_element_info_alter(&$type) {
  if (isset(
$type['text_format']['#process'])) {
    foreach (
$type['text_format']['#process'] as &$callback) {
      if (
$callback === 'filter_process_format') {
       
$callback = 'default_text_format_filter_process_format';
      }
    }
  }
}
/**
* Callback for MODULENAME_element_info_alter().
*/
function default_text_format_filter_process_format($element) {
 
$element = filter_process_format($element);
 
// Change input format to "Filtered HTML" for body fields of article nodes
 
if ($element['#bundle'] == 'article' && $element['#field_name'] == 'body') {
   
$element['format']['format']['#default_value'] = 'filtered_html';
  }
  return
$element;
}
?>