0

I have a customized module that requires tinyMCE as a library.

enter image description here

After module installation, I still have to set my text editor in the image above. It was found in the admin/config/content/wysiwyg.

How will I programatically set tinyMCE as a default text editor right after module installation?

2

Below code is used in wysiwyg_profile_form_submit() at wysiwyg.admin.inc. You can make use of it.

// Insert new profile data.
db_merge('wysiwyg')
  ->key(array('format' => $format))
  ->fields(array(
    'editor' => $editor,
    'settings' => serialize($values),
  ))
  ->execute();
wysiwyg_profile_cache_clear();

Another approach is using drupal_form_submit() to submit its settings form programmatically. But it would be more compliated.

Also, before settings the profile, you need to check if tinymce is existing.

if (wysiwyg_get_editor('tinymce')) {

  // set profile.

}
  • Where will I get the value for $values? – user46175 Aug 4 '16 at 1:53
  • 1
    The $values is from $form_state['values'] (source). It is quite hard to build the array by yourself. You can save the settings first, then copy the value on settings column in table wysiwyg, then use unserialize tool to convert the string into array. – Jimmy Ko Aug 4 '16 at 2:01

Your Answer

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