Created
August 7, 2014 20:45
-
-
Save jameswilson/2dd5bdb0401115656f29 to your computer and use it in GitHub Desktop.
HTML in Title field
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 | |
* html_in_title.features.filter.inc | |
*/ | |
/** | |
* Implements hook_filter_default_formats(). | |
*/ | |
function html_in_title_filter_default_formats() { | |
$formats = array(); | |
// Exported format: Title field. | |
$formats['title_field'] = array( | |
'format' => 'title_field', | |
'name' => 'Title field', | |
'cache' => 1, | |
'status' => 1, | |
'weight' => 0, | |
'filters' => array( | |
'filter_html' => array( | |
'weight' => -10, | |
'status' => 1, | |
'settings' => array( | |
'allowed_html' => '<a> <b> <i> <em> <strong> <code> <span>', | |
'filter_html_help' => 0, | |
'filter_html_nofollow' => 0, | |
), | |
), | |
'filter_htmlcorrector' => array( | |
'weight' => 10, | |
'status' => 1, | |
'settings' => array(), | |
), | |
), | |
); | |
return $formats; | |
} |
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 = HTML in Title | |
description = Uses title module to allow html in title, with custom text format. | |
core = 7.x | |
version = 1.0 | |
dependencies[] = title | |
features[features_api][] = api:2 | |
features[filter][] = title_field |
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 | |
* html_in_title.module | |
*/ | |
/** | |
* Implements of hook_element_info_alter(). | |
*/ | |
function html_in_title_element_info_alter(&$type) { | |
// Our process callback must run immediately after filter_process_format(). | |
$filter_process_format_location = array_search('filter_process_format', $type['text_format']['#process']); | |
$replacement = array('filter_process_format', 'html_in_title_filter_process_format'); | |
array_splice($type['text_format']['#process'], $filter_process_format_location, 1, $replacement); | |
} | |
/** | |
* Process callback for form elements that have a text format selector attached. | |
* | |
* This callback runs after filter_process_format() and performs additional | |
* modifications to the form element. | |
* | |
* @see filter_process_format() | |
*/ | |
function html_in_title_filter_process_format($element) { | |
// Note: this may interfere with Better Formats module! | |
if (isset($element['#field_name']) && $element['#field_name'] == 'title_field') { | |
// The title_field input format should be the *only* option avaible | |
// to Title fields. | |
$element['format']['format']['#default_value'] = 'title_field'; | |
$element['format']['format']['#options'] = array('title_field' => 'Title field'); | |
foreach(element_children($element['format']['guidelines']) as $format) { | |
if ($format != 'title_field'){ | |
unset($element['format']['guidelines'][$format]); | |
} | |
} | |
// Dont show formatting info, dont show help link. | |
$element['format']['format']['#access'] = FALSE; | |
$element['format']['help']['#access'] = FALSE; | |
} else { | |
// The title_field text format should be hidden for *any* field that | |
// is NOT a title_field! | |
unset($element['format']['format']['#options']['title_field']); | |
unset($element['format']['guidelines']['title_field']); | |
// The title_field text format should NOT be used for *any* field that | |
// is NOT a title_field. | |
if ($element['#format'] == 'title_field') { | |
$other_formats = array_keys($element['format']['format']['#options']); | |
$element['#format'] = array_shift($other_formats); | |
} | |
} | |
return $element; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment