Created
February 9, 2016 07:40
-
-
Save rang501/21c8ef421db84f65d982 to your computer and use it in GitHub Desktop.
Add ckeditor to term localize forms
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Implements hook_form_FORM_ID_alter(). | |
* | |
* Add wysiwyg editor to term translation. | |
*/ | |
function module_form_i18n_string_translate_page_form_alter(&$form, $form_state) { | |
$keys = array_keys($form['strings']['all']); | |
$first = reset($keys); | |
if (strpos($first, 'taxonomy:term:') !== FALSE) { | |
$groups = explode(':', $first); | |
$term = taxonomy_term_load($groups[2]); | |
if ($term && $term->vocabulary_machine_name == 'kkk') { | |
$element = &$form['strings']['all']['taxonomy:term:' . $term->tid . ':description']; | |
if (!$element['#disabled']) { | |
$element['#type'] = 'text_format'; | |
$element['#rows'] = 10; | |
$element['#format'] = $term->format; | |
$element['#element_validate'][] = 'module_validate_term_translation_description'; | |
} | |
} | |
} | |
} | |
/** | |
* Validation for term translation description. | |
* | |
* Text format changes the value structure, so we need to change it back or we | |
* see awful error. | |
*/ | |
function module_validate_term_translation_description($element, &$form_state, $form) { | |
foreach($form_state['values']['strings'] as &$value) { | |
if (is_array($value)) { | |
$value = $value['value']; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment