Created
January 3, 2012 09:15
-
-
Save blackice2999/1554210 to your computer and use it in GitHub Desktop.
Drupal: Text Formatter Plaintext trimmed
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 | |
function evt_news_field_formatter_info() { | |
return array( | |
'text_plain_trimmed' => array( | |
'label' => t('Plain text (trimmed)'), | |
'field types' => array('text', 'text_long', 'text_with_summary'), | |
'settings' => array('trim_length' => 300), | |
)); | |
} | |
function evt_news_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) { | |
return text_field_formatter_settings_form($field, $instance, $view_mode, $form, $form_state); | |
} | |
/** | |
* Implements hook_field_formatter_settings_summary(). | |
*/ | |
function evt_news_field_formatter_settings_summary($field, $instance, $view_mode) { | |
return text_field_formatter_settings_summary($field, $instance, $view_mode); | |
} | |
/** | |
* Implements hook_field_formatter_view(). | |
*/ | |
function evt_news_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) { | |
$element = array(); | |
switch ($display['type']) { | |
case 'text_plain_trimmed': | |
foreach ($items as $delta => $item) { | |
$output = _text_sanitize($instance, $langcode, $item, 'value'); | |
$output = strip_tags($output); | |
if ($display['type'] == 'text_plain_trimmed') { | |
$output = text_summary($output, $instance['settings']['text_processing'] ? $item['format'] : NULL, $display['settings']['trim_length']); | |
} | |
$element[$delta] = array('#markup' => $output); | |
} | |
break; | |
} | |
return $element; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment