protected ConfigImporter::checkOp($collection, $op, $name)
Checks that the operation is still valid.
During a configuration import secondary writes and deletes are possible. This method checks that the operation is still valid before processing a configuration change.
Parameters
string $collection: The configuration collection.
string $op: The change operation.
string $name: The name of the configuration to process.
Return value
bool TRUE is to continue processing, FALSE otherwise.
Throws
\Drupal\Core\Config\ConfigImporterException
File
- core/lib/Drupal/Core/Config/ConfigImporter.php, line 831
Class
- ConfigImporter
- Defines a configuration importer.
Namespace
Drupal\Core\Config
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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | protected function checkOp( $collection , $op , $name ) { if ( $op == 'rename' ) { $names = $this ->storageComparer->extractRenameNames( $name ); $target_exists = $this ->storageComparer->getTargetStorage( $collection )->exists( $names [ 'new_name' ]); if ( $target_exists ) { // If the target exists, the rename has already occurred as the // result of a secondary configuration write. Change the operation // into an update. This is the desired behavior since renames often // have to occur together. For example, renaming a node type must // also result in renaming its fields and entity displays. $this ->storageComparer->moveRenameToUpdate( $name ); return FALSE; } return TRUE; } $target_exists = $this ->storageComparer->getTargetStorage( $collection )->exists( $name ); switch ( $op ) { case 'delete' : if (! $target_exists ) { // The configuration has already been deleted. For example, a field // is automatically deleted if all the instances are. $this ->setProcessedConfiguration( $collection , $op , $name ); return FALSE; } break ; case 'create' : if ( $target_exists ) { // If the target already exists, use the entity storage to delete it // again, if is a simple config, delete it directly. if ( $entity_type_id = $this ->configManager->getEntityTypeIdByName( $name )) { $entity_storage = $this ->configManager->getEntityManager()->getStorage( $entity_type_id ); $entity_type = $this ->configManager->getEntityManager()->getDefinition( $entity_type_id ); $entity = $entity_storage ->load( $entity_storage ->getIDFromConfigName( $name , $entity_type ->getConfigPrefix())); $entity -> delete (); $this ->logError( $this ->t( 'Deleted and replaced configuration entity "@name"' , array ( '@name' => $name ))); } else { $this ->storageComparer->getTargetStorage( $collection )-> delete ( $name ); $this ->logError( $this ->t( 'Deleted and replaced configuration "@name"' , array ( '@name' => $name ))); } return TRUE; } break ; case 'update' : if (! $target_exists ) { $this ->logError( $this ->t( 'Update target "@name" is missing.' , array ( '@name' => $name ))); // Mark as processed so that the synchronization continues. Once the // the current synchronization is complete it will show up as a // create. $this ->setProcessedConfiguration( $collection , $op , $name ); return FALSE; } break ; } return TRUE; } |
Please login to continue.