Skip to content
Snippets Groups Projects
Commit efb7568b authored by Steve Wirt's avatar Steve Wirt
Browse files

Consilidate methods for preparing drupal titles.

parent 62a77444
Branches 7.x-1.x
Tags
No related merge requests found
migration_tools 7.x-1.x **-**-****
migration_tools 7.x-1.x ** - ** - ****
-----------------------------------------------
* Consolidate methods for cleaning node titles.
* Add CHANGELOG.md
* Moved URL and redirect related methods into UrlTools.inc
......
......@@ -148,11 +148,6 @@ abstract class MTBaseMigration extends Migration {
public function prepareRow($row) {
parent::prepareRow($row);
// Prepare title property by trimming to 255 chars and fixing encoding.
if (!empty($row->title)) {
$row->title = mb_strimwidth($row->title, 0, 255, "...");
$row->title = html_entity_decode($row->title, ENT_QUOTES, 'UTF-8');
}
}
/**
......
......@@ -393,6 +393,21 @@ class StringCleanUp {
return $string;
}
/**
* Prepares a string to be a Drupal node title.
*
* @param string $string
* The string to be cleaned.
*
* @return string
* The string html decoded, capped and trimmed.
*/
public static function cleanTitle($string) {
$string = ObtainTitle::cleanString($string);
$string = ObtainTitle::truncateString($string);
return $string;
}
/**
* Callback helper.
*/
......
......@@ -26,8 +26,11 @@ class ObtainTitle extends ObtainHtml {
protected function truncateString($string) {
$split = $this->truncateThisWithoutHTML($string, 255, 2);
// @todo Add debugging to display $split['remaining'].
// $this->setTextDiscarded($split['remaining']);
// If something got trimmed off, message it.
if (!empty($split['remaining'])) {
$message = "The title was shortened and lost: @remainder";
MigrationMessage::makeMessage($message, array('@remainder' => $split['remaining']), WATCHDOG_ERROR, 2);
}
return $split['truncated'];
}
......@@ -51,7 +54,7 @@ class ObtainTitle extends ObtainHtml {
return $this->findSubBannerAttr('title');
}
/**
/**
* Grab method to find the content sub-banner attribute.
* @return string
* The text found.
......@@ -103,7 +106,7 @@ class ObtainTitle extends ObtainHtml {
$text = str_ireplace($break_tags, ' ', $text);
$text = strip_tags($text);
// Titles can not have html entities.
$text = html_entity_decode($text, ENT_COMPAT, 'UTF-8');
$text = html_entity_decode($text, ENT_QUOTES, 'UTF-8');
// There are also numeric html special chars, let's change those.
module_load_include('inc', 'migration_tools', 'includes/migration_tools');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment