Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
The following example is pending the patch found at https://www.drupal.org/node/2503815
class MyCustomFlagMigration extends DrupalMigration {
public function __construct($arguments) {
parent::__construct($arguments);
// requires the flag name of the source flag in query() below
$this->sourceFlag = 'bookmarks';
// requires the fid of the destination flag
$this->destFlag = flag_get_flag('bookmarks');
$this->description = t('My awesome bookmark flag migration.');
$this->source = new MigrateSourceSQL($this->query());
$this->destination = new MigrateDestinationFlag($this->destFlag->fid);
// source schema from Flag-7.x-2.x
$this->map = new MigrateSQLMap($this->machineName,
array(
'fcid' => array(
'type' => 'int',
'not null' => TRUE,
'description' => 'Source Flag CID',
)
),
MigrateDestinationFlag::getKeySchema()
);
// map fields including example source migrations Article and User
$this->addFieldMapping('fid', $this->destFlag->fid);
$this->addFieldMapping('entity_id', 'content_id')->sourceMigration('Article');
$this->addFieldMapping('uid', 'uid')->sourceMigration('User');
$this->addFieldMapping('entity_type', 'content_type');
$this->addSimpleMappings(array('timestamp'));
}
public function query() {
// query 'flag_content' for a Flag-7.x-2.x table schema
$query = Database::getConnection('default', $this->sourceConnection)
->select('flag_content', 'fc')
->fields('fc', array(
'fcid',
'fid',
'content_type',
'content_id',
'uid',
'timestamp'
));
// find flags matching this flag machine name
$query->leftJoin('flags', 'f', 'f.fid=fc.fid');
$query->condition('f.name', $this->sourceFlag, '=');
return $query;
}
}