Drupal Filter Form Input

This fragment of the drupal form will provide me with a text box in which the user can change the filter to full html / wysiwyg mode.

My questions are: how can I use full html mode by default?

function MY_MODULE_admin() {
  $form = array();

 $form['format'] = filter_form($form->format);

  // MY_MODULE - ** Image 1 **
    $form['MY_MODULE_image_1'] = array(
    '#type' => 'textarea',
    '#title' => t('Image 1'),
    '#default_value' => variable_get('setup_image_1', 'image_1.jpg'),
    '#description' => "Current value =" .variable_get('setup_image_1', 'image_1.jpg'),
    '#required' => TRUE,
  );
+3
source share
4 answers

It did the trick.

 $form = array();

 $form['carousel_setup_image_1']['accepted_text_1'] = array(
    '#type' => 'textarea',
    '#title' => t('Image 1 - Carousel '),
    '#default_value' => variable_get('carousel_setup_image_1', 'carousel_image_1.jpg'),
    '#description' => "Current value =" .variable_get('carousel_setup_image_1', 'carousel_image_1.jpg'),
  ); 
  $form['carousel_setup_image_1']['format'] = filter_form(2, NULL, array('accepted_text_1_format'));    
+3
source

Well there are two ways.

First, you can set this default format for full HTML in the "Input Formats" section.

Two, you can say $ form ['format'] ['# default_value'] = 2 (I think Full HTML is 2). This will allow you to select the full HTML code.

0
source
however, I am not sure why $edit['carousel_setup_image_1']['accepted_text_1']) does not contain entered value.

function carousel_setup_block($op = 'list', $delta = 0, $edit = array())
{
       switch($op)
        {

            // case save (save configuration values)       
            case 'save':
            variable_set('carousel_setup_image_1',                
                    $edit['carousel_setup_image_1']['accepted_text_1']);
                break;           
        }   
    }
0

For Drupal 7: the best way to process (or use) the Drupal text filter system is to use not the "textarea", but the type of the text_format field like this, which will display the text field with the filter selected below

      $form['holycrap'] = array(
        '#type' => 'text_format',
        '#format' => NULL, // <- Let Drupal handle the default, based upon user role
        '#title' => t('The HTML for the Holy Crap block above the Main Menu.'),
        '#default_value' => variable_get('caplogin_holycrap', _caplogin_holycrap_default_html()),
      );
     return $form;
0
source

Source: https://habr.com/ru/post/1749293/


All Articles