public static function MigrateDestinationMedia::rewriteImgTags in Migrate Extras 7.2
Call this from the prepare() method of a migration that contains media image files, if you want to rewrite the IMG tags into media references.
Parameters
$entity: Entity object being built.
$field: Name of the text field within the entity to be modified. Defaults to 'body'.
1 call to MigrateDestinationMedia::rewriteImgTags()
- MigrateExampleMediaNodeMigration::prepare in migrate_extras_examples/
migrate_extras_media/ migrate_extras_media.migrate.inc - Implementation of Migration::prepare().
File
- ./
media.inc, line 16
Class
- MigrateDestinationMedia
- Destination class implementing migration into media entities.
Code
public static function rewriteImgTags($entity, $field = 'body') {
if (is_array($entity->{$field})) {
migrate_instrument_start('MigrateDestinationMedia rewriteImgTags');
foreach ($entity->{$field} as $language => $values) {
$body = $values[0]['value'];
break;
}
// Quickly skip any non-candidates
if (!stristr($body, '<img')) {
migrate_instrument_stop('MigrateDestinationMedia rewriteImgTags');
return;
}
// Pass full img tags into the callback
$new_body = preg_replace_callback('|<img [^>]*>|i', array(
self,
'replaceCallback',
), $body);
$entity->{$field}[$language][0]['value'] = $new_body;
migrate_instrument_stop('MigrateDestinationMedia rewriteImgTags');
}
}