I have some sample code here. basically i altered a block and added a textarea with wysiwyg. that works and is ok. the problem is how do i render wysiwyg created text, so that all filters like media, token are processed?
$html_text['content']['custom_html_text']['#theme'] = 'item_list'; is just an example. is there a theming function i must use here to get this proecessed?

/*
 * hook_form_alter
 *
 */

function example_form_alter(&$form, &$form_state, $form_id) {
  $foo = 1;

  if ($form_id == 'facetapi_facet_display_form') {

    //we need an id to save the textvalue
    $id = $form['#facetapi']['facet']['field'];
    //add custom html textarea
    $form['html_text'] = array(
      '#title' => t('Your custom HTML'),
      '#type' => 'text_format',
      '#description' => t('Custom HTML that will be displayed above the facet'),
      '#format' => 'full_html',
      '#rows' => 50,
      '#default_value' => variable_get("html_text_" . $id . "value", 'foo')

    );
    $form['#submit'][] = 'example_form_submit';
  }
}

function example_form_submit($form, &$form_state) {

  $id = $form['#facetapi']['facet']['field'];
  $html_text = $form_state['values']['html_text']['value'];
  variable_set("html_text_" . $id . "value", $html_text);
}


/*
 * hook_block_view_alter()
 */

function example_block_view_alter(&$data, $block) {

  if ($block->module == 'facetapi') {
    //get custom text
    $custom_text = $data['content']['#settings']->settings['html_text']['value'];

    if (!empty($custom_text)) {
      $html_text['content']['custom_html_text']['#theme'] = 'item_list';
      $html_text['content']['custom_html_text']['#items'][]['data'] = $custom_text;
      $html_text['custom_html_text']['#attributes']['class'][0] = 'custom_facetapi_text';

//      $data['content']['custom_html_text']['#theme'] = 'item_list';
//      $data['content']['custom_html_text']['#items'][]['data'] = $custom_text;
//      $data['content']['custom_html_text']['#attributes']['class'][0] = 'custom_facetapi_text';

      //we can put the text at the top
      $data['content'] = array_merge($html_text, $data['content']);

    }


  }

Comments

marcoka’s picture

Title: Render custom textfield taht ises wysiwyg » Render custom textfield that uses wysiwyg
TwoD’s picture

Status: Active » Fixed

You use the regular check_markup() function you always use to render any input with markup.

Wysiwyg module runs no code at all in the rendering process, everything is handled when the form is generated on the server, and before the input is sent back to the server from the client.

Btw, this means you must also store the format the user selected ($form_state['values']['html_text']['format']) along with the actual markup.

Also, I would not recommend storing the value with set_variable(), since these variables are meant for small amounts of data needed often. All the variables get saved to the same database table and all of them are loaded during Drupal's bootstrap process into a global variable. If the user puts a lot of content in there, it'll eat that amount of memory on all page loads.

marcoka’s picture

thnak you very much.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.