Created
September 9, 2013 07:57
-
-
Save vdchristelle/6492661 to your computer and use it in GitHub Desktop.
Drupal doesn't put a CKeditor default on the summary of the body field.
This module does :)
This file contains hidden or 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
| Drupal doesn't put a CKeditor default on the summary of the body field. | |
| This module does :) |
This file contains hidden or 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
| name = "Summary's CKeditor" | |
| description = "Module puts CKeditor on the Summary of the body field." | |
| core = "7.x" | |
| package = Fix | |
| php = "5.2.4" | |
| version = "7.x-1.0" | |
| project = "custom" | |
| ;dependencies[] = "ckeditor" | |
| dependencies[] = "wysiwyg" |
This file contains hidden or 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
| <?php | |
| /** | |
| * @file | |
| * Custom code for your dupal 7 site | |
| */ | |
| /** | |
| * Implements hook_help(). | |
| */ | |
| function summaryeditor_help($path, $arg) { | |
| $output = NULL; | |
| switch ($path) { | |
| case 'admin/help#summaryeditor': | |
| //$output = file_get_contents(drupal_get_path('module', 'the_aim_custom') . '/README.txt'); | |
| //return nl2br($output); | |
| return t('<h1>A fix for CKeditor on Summary body field.</h1> | |
| <p>Drupal doesn\'t put a CKeditor default on the summary of the body field. This module does ;)</h2> | |
| <h2>Usefull links:</h2> | |
| <ul> | |
| <li>Blog: <a href="http://theunraveler.com/blog/2012/drupal-7-how-add-wysiwyg-editor-text-summary-field/" target="_blank">blog post</a></li> | |
| <li>Drupal API: <a href="http://api.drupal.org/api/drupal/modules!field!field.api.php/function/hook_field_widget_form_alter/7" target="_blank">function hook_field_widget_form_alter(&$element, &$form_state, $context)</a></li> | |
| </ul> | |
| '); | |
| } | |
| return $output; | |
| } | |
| /** | |
| * Implementation of hook_field_widget_form_alter(). | |
| * | |
| * Add WYSIWYG treatment to textarea summary form items. | |
| */ | |
| function summaryeditor_field_widget_form_alter(&$element, &$form_state, $context) { | |
| if (isset($element['summary'])) { | |
| drupal_add_css(drupal_get_path('module', 'summaryeditor') . '/assets/textarea-summary.css'); | |
| drupal_add_js(drupal_get_path('module', 'summaryeditor') . '/assets/textarea-summary.js'); | |
| $element['summary']['#type'] = 'text_format'; | |
| $element['summary']['#format'] = $element['#format']; | |
| } | |
| } | |
| /** | |
| * Implements hook_field_attach_presave(). | |
| */ | |
| function summaryeditor_field_attach_presave($entity_type, $entity) { | |
| list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity); | |
| foreach (field_info_instances($entity_type, $bundle) as $instance) { | |
| $field = field_info_field_by_id($instance['field_id']); | |
| $field_name = $field['field_name']; | |
| if ($field['type'] == 'text_with_summary' && !empty($entity->$field_name)) { | |
| $language = isset($entity->language) ? $entity->language : LANGUAGE_NONE; | |
| foreach ($entity->$field_name[$language] as $id => &$value) { | |
| if (is_array($value['summary'])) { | |
| $value['summary'] = $value['summary']['value']; | |
| } | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment