class MigratePathEntityHandler in Migrate 7.2
@file Support for paths in core Drupal objects
Hierarchy
- class \MigrateHandler
- class \MigrateDestinationHandler
- class \MigratePathEntityHandler
- class \MigrateDestinationHandler
Expanded class hierarchy of MigratePathEntityHandler
1 string reference to 'MigratePathEntityHandler'
File
- plugins/
destinations/ path.inc, line 8 - Support for paths in core Drupal objects
View source
class MigratePathEntityHandler extends MigrateDestinationHandler {
public function __construct() {
$this
->registerTypes(array(
'entity',
));
}
/**
* Implementation of MigrateDestinationHandler::fields().
*/
public function fields($entity_type, $bundle, $migration = NULL) {
if (module_exists('path')) {
return array(
'path' => t('Path alias'),
);
}
return array();
}
public function prepare($entity, stdClass $row) {
if (module_exists('path') && isset($entity->path)) {
// Make sure the alias doesn't already exist
$query = db_select('url_alias')
->condition('alias', $entity->path)
->condition('language', $entity->language);
$query
->addExpression('1');
$query
->range(0, 1);
if (!$query
->execute()
->fetchField()) {
$path = $entity->path;
$entity->path = array();
$entity->path['alias'] = $path;
}
else {
unset($entity->path);
}
}
}
public function complete($entity, stdClass $row) {
// Check if this is a forum taxonomy term.
if (module_exists('forum')) {
if (isset($entity->vocabulary_machine_name) && $entity->vocabulary_machine_name == 'forums') {
// Check if a path ID exists for this term.
$term_pid = db_select('url_alias', 'url_alias')
->fields('url_alias', array(
'pid',
))
->condition('source', 'taxonomy/term/' . $entity->tid)
->condition('language', $entity->language)
->execute()
->fetchField();
// Check if there is also a path ID for this term referencing forums.
$forum_term_pid = db_select('url_alias', 'url_alias')
->fields('url_alias', array(
'pid',
))
->condition('source', 'forum/' . $entity->tid)
->condition('language', $entity->language)
->execute()
->fetchField();
// If both term and forum term path IDs exist, delete the term's path.
if ($term_pid && $forum_term_pid) {
db_delete('url_alias')
->condition('pid', $term_pid)
->execute();
}
elseif ($term_pid && empty($forum_term_pid)) {
db_update('url_alias')
->fields(array(
'source' => 'forum/' . $entity->tid,
))
->condition('pid', $term_pid)
->execute();
}
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MigrateHandler:: |
protected | property | List of other handler classes which should be invoked before the current one. | |
MigrateHandler:: |
protected | property | List of "types" handled by this handler. Depending on the kind of handler, these may be destination types, field types, etc. | |
MigrateHandler:: |
public | function | ||
MigrateHandler:: |
public | function | ||
MigrateHandler:: |
public | function | Does this handler handle the given type? | 1 |
MigrateHandler:: |
protected | function | Register a list of types handled by this class | |
MigratePathEntityHandler:: |
public | function | ||
MigratePathEntityHandler:: |
public | function | Implementation of MigrateDestinationHandler::fields(). | |
MigratePathEntityHandler:: |
public | function | ||
MigratePathEntityHandler:: |
public | function |
Overrides MigrateHandler:: |