public BaseFieldOverride::preSave(EntityStorageInterface $storage)
Throws
\Drupal\Core\Field\FieldException If the bundle is being changed.
Overrides ConfigEntityBase::preSave
File
- core/lib/Drupal/Core/Field/Entity/BaseFieldOverride.php, line 163
Class
- BaseFieldOverride
- Defines the base field override entity.
Namespace
Drupal\Core\Field\Entity
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 | public function preSave(EntityStorageInterface $storage ) { // Filter out unknown settings and make sure all settings are present, so // that a complete field definition is passed to the various hooks and // written to config. $field_type_manager = \Drupal::service( 'plugin.manager.field.field_type' ); $default_settings = $field_type_manager ->getDefaultFieldSettings( $this -> getType ()); $this ->settings = array_intersect_key ( $this ->settings, $default_settings ) + $default_settings ; // Call the parent's presave method to perform validate and calculate // dependencies. parent::preSave( $storage ); if ( $this ->isNew()) { // @todo This assumes that the previous definition isn't some // non-config-based override, but that might not be the case: $previous_definition = $this ->getBaseFieldDefinition(); } else { // Some updates are always disallowed. if ( $this ->entity_type != $this ->original->entity_type) { throw new FieldException( "Cannot change the entity_type of an existing base field bundle override (entity type:{$this->entity_type}, bundle:{$this->original->bundle}, field name: {$this->field_name})" ); } if ( $this ->bundle != $this ->original->bundle) { throw new FieldException( "Cannot change the bundle of an existing base field bundle override (entity type:{$this->entity_type}, bundle:{$this->original->bundle}, field name: {$this->field_name})" ); } $previous_definition = $this ->original; } // Notify the entity storage. $this ->entityManager()->getStorage( $this ->getTargetEntityTypeId())->onFieldDefinitionUpdate( $this , $previous_definition ); } |
Please login to continue.