Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. EntityFile.php

function EntityFile::processStubRow

Overrides EntityContentBase::processStubRow

File

core/modules/file/src/Plugin/migrate/destination/EntityFile.php, line 45

Class

EntityFile
Provides migrate destination plugin for File entities.

Namespace

Drupal\file\Plugin\migrate\destination

Code

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->entityFieldManager
            ->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 = mb_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);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal