public ViewsEntitySchemaSubscriber::onEntityTypeUpdate(EntityTypeInterface $entity_type, EntityTypeInterface $original)
Reacts to the update of the entity type.
Parameters
\Drupal\Core\Entity\EntityTypeInterface $entity_type: The updated entity type definition.
\Drupal\Core\Entity\EntityTypeInterface $original: The original entity type definition.
Overrides EntityTypeEventSubscriberTrait::onEntityTypeUpdate
File
- core/modules/views/src/EventSubscriber/ViewsEntitySchemaSubscriber.php, line 97
Class
- ViewsEntitySchemaSubscriber
- Reacts to changes on entity types to update all views entities.
Namespace
Drupal\views\EventSubscriber
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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | public function onEntityTypeUpdate(EntityTypeInterface $entity_type , EntityTypeInterface $original ) { $changes = []; // We implement a specific logic for table updates, which is bound to the // default sql content entity storage. if (! $this ->entityManager->getStorage( $entity_type ->id()) instanceof SqlContentEntityStorage) { return ; } if ( $entity_type ->getBaseTable() != $original ->getBaseTable()) { $changes [] = static ::BASE_TABLE_RENAME; } $revision_add = $entity_type ->isRevisionable() && ! $original ->isRevisionable(); $revision_remove = ! $entity_type ->isRevisionable() && $original ->isRevisionable(); $translation_add = $entity_type ->isTranslatable() && ! $original ->isTranslatable(); $translation_remove = ! $entity_type ->isTranslatable() && $original ->isTranslatable(); if ( $revision_add ) { $changes [] = static ::REVISION_TABLE_ADDITION; } elseif ( $revision_remove ) { $changes [] = static ::REVISION_TABLE_REMOVAL; } elseif ( $entity_type ->isRevisionable() && $entity_type ->getRevisionTable() != $original ->getRevisionTable()) { $changes [] = static ::REVISION_TABLE_RENAME; } if ( $translation_add ) { $changes [] = static ::DATA_TABLE_ADDITION; } elseif ( $translation_remove ) { $changes [] = static ::DATA_TABLE_REMOVAL; } elseif ( $entity_type ->isTranslatable() && $entity_type ->getDataTable() != $original ->getDataTable()) { $changes [] = static ::DATA_TABLE_RENAME; } if ( $entity_type ->isRevisionable() && $entity_type ->isTranslatable()) { if ( $revision_add || $translation_add ) { $changes [] = static ::REVISION_DATA_TABLE_ADDITION; } elseif ( $entity_type ->getRevisionDataTable() != $original ->getRevisionDataTable()) { $changes [] = static ::REVISION_DATA_TABLE_RENAME; } } elseif ( $original ->isRevisionable() && $original ->isTranslatable() && ( $revision_remove || $translation_remove )) { $changes [] = static ::REVISION_DATA_TABLE_REMOVAL; } /** @var \Drupal\views\Entity\View[] $all_views */ $all_views = $this ->entityManager->getStorage( 'view' )->loadMultiple(NULL); foreach ( $changes as $change ) { switch ( $change ) { case static ::BASE_TABLE_RENAME: $this ->baseTableRename( $all_views , $entity_type ->id(), $original ->getBaseTable(), $entity_type ->getBaseTable()); break ; case static ::DATA_TABLE_RENAME: $this ->dataTableRename( $all_views , $entity_type ->id(), $original ->getDataTable(), $entity_type ->getDataTable()); break ; case static ::DATA_TABLE_ADDITION: $this ->dataTableAddition( $all_views , $entity_type , $entity_type ->getDataTable(), $entity_type ->getBaseTable()); break ; case static ::DATA_TABLE_REMOVAL: $this ->dataTableRemoval( $all_views , $entity_type ->id(), $original ->getDataTable(), $entity_type ->getBaseTable()); break ; case static ::REVISION_TABLE_RENAME: $this ->baseTableRename( $all_views , $entity_type ->id(), $original ->getRevisionTable(), $entity_type ->getRevisionTable()); break ; case static ::REVISION_TABLE_ADDITION: // If we add revision support we don't have to do anything. break ; case static ::REVISION_TABLE_REMOVAL: $this ->revisionRemoval( $all_views , $original ); break ; case static ::REVISION_DATA_TABLE_RENAME: $this ->dataTableRename( $all_views , $entity_type ->id(), $original ->getRevisionDataTable(), $entity_type ->getRevisionDataTable()); break ; case static ::REVISION_DATA_TABLE_ADDITION: $this ->dataTableAddition( $all_views , $entity_type , $entity_type ->getRevisionDataTable(), $entity_type ->getRevisionTable()); break ; case static ::REVISION_DATA_TABLE_REMOVAL: $this ->dataTableRemoval( $all_views , $entity_type ->id(), $original ->getRevisionDataTable(), $entity_type ->getRevisionTable()); break ; } } foreach ( $all_views as $view ) { // All changes done to the views here can be trusted and this might be // called during updates, when it is not safe to rely on configuration // containing valid schema. Trust the data and disable schema validation // and casting. $view ->trustData()->save(); } } |
Please login to continue.