protected function EntityFile::processStubRow in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/file/src/Plugin/migrate/destination/EntityFile.php \Drupal\file\Plugin\migrate\destination\EntityFile::processStubRow()
Do as much population of the stub row as we can.
Parameters
\Drupal\migrate\Row $row: The row of data.
Overrides EntityContentBase::processStubRow
File
- core/
modules/ file/ src/ Plugin/ migrate/ destination/ EntityFile.php, line 278 - Contains \Drupal\file\Plugin\migrate\destination\EntityFile.
Class
- EntityFile
- Every migration that uses this destination must have an optional dependency on the d6_file migration to ensure it runs first.
Namespace
Drupal\file\Plugin\migrate\destinationCode
protected function processStubRow(Row $row) {
// We stub the uri value ourselves so we can create a real stub file for it.
if (!$row
->getDestinationProperty('uri')) {
$field_definitions = $this->entityManager
->getFieldDefinitions($this->storage
->getEntityTypeId(), $this
->getKey('bundle'));
$value = UriItem::generateSampleValue($field_definitions['uri']);
if (empty($value)) {
throw new MigrateException('Stubbing failed, unable to generate value for field uri');
}
// generateSampleValue() wraps the value in an array.
$value = reset($value);
// Make it into a proper public file uri, stripping off the existing
// scheme if present.
$value = 'public://' . preg_replace('|^[a-z]+://|i', '', $value);
$value = Unicode::substr($value, 0, $field_definitions['uri']
->getSetting('max_length'));
// Create a real file, so File::preSave() can do filesize() on it.
touch($value);
$row
->setDestinationProperty('uri', $value);
}
parent::processStubRow($row);
}