0

I am trying to write a custom form for my own search facet. In the form, the labels of the elements are dinamically generated based on the indexed values, and they can contain special Hungarian characters, which are not displayed correctly. This is my code:

  $form['facets'][$current_property] = array(
    '#type' => 'select',
    '#title' => $current_property,
    '#multiple' => TRUE,
    '#options' => $myoptions,
    '#default_value' => $widget->buildDefaultValue($element),
    '#attributes' => array('class' => array('facetapi-multiselect', $form_state['facetapi_multiselect']['facet_class'])),
    '#post_render' => array('_facetapi_multiselect_modified_disable_options'),
    );      

So, for example, if $current_property is Belső memória/tárhely, then Bels? memória/tárhely is displayed in the search facet.

Can you suggest any ways how to do this correctly? Thank you very much in advance.

0

Based on the version of drupal you are using, you can use one of functions below :

decode_entities($text) for Drupal 7

or

Html::decodeEntities($text) for Drupal 8

so in case of using drupal 7, Your code will looks like this:

$form['facets'][$current_property] = array(
  '#type' => 'select',
  '#title' => decode_entities($current_property),
  '#multiple' => TRUE,
  '#options' => $myoptions,
  '#default_value' => $widget->buildDefaultValue($element),
  '#attributes' => array('class' => array('facetapi-multiselect', 
    $form_state['facetapi_multiselect']['facet_class'])),
  '#post_render' => array('_facetapi_multiselect_modified_disable_options'),
);  
|improve this answer|||||
  • Unfortunately, it did not help, I still see question mark (?) instead of ő. – VLaci Jul 1 '18 at 13:30
  • Maybe you can use iconv('ISO-8859-1', 'UTF-8', $current_property); – Alireza Tabatabaeian Jul 2 '18 at 8:09
0

Maybe there is a problem in collation settings when you want to get data from database

  1. Try to use another collation like utf8mb4_bin or utf8_bin.

  2. Try to debug the value of $current_property and see what you have there.

  3. Maybe your font doesn't support special symbols.

Good luck!

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.