protected static ConfigImporterFieldPurger::initializeSandbox(array &$context, ConfigImporter $config_importer)
Initializes the batch context sandbox for processing field deletions.
This calculates the number of steps necessary to purge all the field data and saves data for later use.
Parameters
array $context: The batch context.
\Drupal\Core\Config\ConfigImporter $config_importer: The config importer.
File
- core/modules/field/src/ConfigImporterFieldPurger.php, line 65
Class
- ConfigImporterFieldPurger
- Processes field purges before a configuration synchronization.
Namespace
Drupal\field
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | protected static function initializeSandbox( array & $context , ConfigImporter $config_importer ) { $context [ 'sandbox' ][ 'field' ][ 'purge_batch_size' ] = \Drupal::config( 'field.settings' )->get( 'purge_batch_size' ); // Save the future list of installed extensions to limit the amount of times // the configuration is read from disk. $context [ 'sandbox' ][ 'field' ][ 'extensions' ] = $config_importer ->getStorageComparer()->getSourceStorage()->read( 'core.extension' ); $context [ 'sandbox' ][ 'field' ][ 'steps_to_delete' ] = 0; $fields = static ::getFieldStoragesToPurge( $context [ 'sandbox' ][ 'field' ][ 'extensions' ], $config_importer ->getUnprocessedConfiguration( 'delete' )); foreach ( $fields as $field ) { $row_count = \Drupal::entityManager()->getStorage( $field ->getTargetEntityTypeId()) ->countFieldData( $field ); if ( $row_count > 0) { // The number of steps to delete each field is determined by the // purge_batch_size setting. For example if the field has 9 rows and the // batch size is 10 then this will add 1 step to $number_of_steps. $how_many_steps = ceil ( $row_count / $context [ 'sandbox' ][ 'field' ][ 'purge_batch_size' ]); $context [ 'sandbox' ][ 'field' ][ 'steps_to_delete' ] += $how_many_steps ; } } // Each field possibly needs one last field_purge_batch() call to remove the // last field and the field storage itself. $context [ 'sandbox' ][ 'field' ][ 'steps_to_delete' ] += count ( $fields ); $context [ 'sandbox' ][ 'field' ][ 'current_progress' ] = 0; } |
Please login to continue.