Добавляем поддержку Wysiwyg для teaser

  1. /**
  2.  * Implementation of hook_field_widget_form_alter().
  3.  *
  4.  * Add WYSIWYG treatment to textarea summary form items.
  5.  */
  6. function MY_MODULE_field_widget_form_alter(&$element, &$form_state, $context) {
  7. if (!isset($element['summary'])) {
  8. return;
  9. }
  10.  
  11. drupal_add_css(drupal_get_path('module', 'MY_MODULE') . '/assets/textarea-summary.css');
  12. drupal_add_js(drupal_get_path('module', 'MY_MODULE') . '/assets/textarea-summary.js');
  13. $element['summary']['#type'] = 'text_format';
  14. $element['summary']['#format'] = $element['#format'];
  15. }
  16.  
  17. /**
  18.  * Implements hook_field_attach_presave().
  19.  */
  20. function MY_MODULE_field_attach_presave($entity_type, $entity) {
  21. list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
  22.  
  23. foreach (field_info_instances($entity_type, $bundle) as $instance) {
  24. $field = field_info_field_by_id($instance['field_id']);
  25. $field_name = $field['field_name'];
  26. if ($field['type'] !== 'text_with_summary' || empty($entity->$field_name)) {
  27. continue;
  28. }
  29.  
  30. $language = isset($entity->language) ? $entity->language : LANGUAGE_NONE;
  31. foreach ($entity->{$field_name}[$language] as $id => &$value) {
  32. if (!is_array($value['summary'])) {
  33. continue;
  34. }
  35.  
  36. $value['summary'] = $value['summary']['value'];
  37. }
  38. }
  39. }

Добавляем в css
div.text-summary-wrapper fieldset.filter-wrapper { display: none; }

Добавляем в js файл

  1. (function ($) {
  2.  
  3. Drupal.behaviors.myModuleTextareaSummary = {
  4. attach: function (context, settings) {
  5.  
  6. // Change the value of the summary format whenever the main textarea
  7. // format changes.
  8. $('.field-type-text-with-summary div.text-format-wrapper > fieldset.filter-wrapper select').change(function(event) {
  9. var value = $(this).val();
  10. $('.text-summary-wrapper select', $(this).closest('.text-format-wrapper')).val(value);
  11. });
  12.  
  13. }
  14. };
  15.  
  16. }(jQuery));
Russian
Категория: 
The code has been tested and works
Мультитег: