comparison core/modules/field/src/Entity/FieldStorageConfig.php @ 18:af1871eacc83

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:33:08 +0100
parents 129ea1e6d783
children
comparison
equal deleted inserted replaced
17:129ea1e6d783 18:af1871eacc83
335 throw new FieldException("Attempt to create a field storage of unknown type {$this->getType()}."); 335 throw new FieldException("Attempt to create a field storage of unknown type {$this->getType()}.");
336 } 336 }
337 $this->module = $field_type['provider']; 337 $this->module = $field_type['provider'];
338 338
339 // Notify the entity manager. 339 // Notify the entity manager.
340 $entity_manager->onFieldStorageDefinitionCreate($this); 340 \Drupal::service('field_storage_definition.listener')->onFieldStorageDefinitionCreate($this);
341 } 341 }
342 342
343 /** 343 /**
344 * {@inheritdoc} 344 * {@inheritdoc}
345 */ 345 */
364 * @param \Drupal\Core\Entity\EntityStorageInterface $storage 364 * @param \Drupal\Core\Entity\EntityStorageInterface $storage
365 * The entity storage. 365 * The entity storage.
366 */ 366 */
367 protected function preSaveUpdated(EntityStorageInterface $storage) { 367 protected function preSaveUpdated(EntityStorageInterface $storage) {
368 $module_handler = \Drupal::moduleHandler(); 368 $module_handler = \Drupal::moduleHandler();
369 $entity_manager = \Drupal::entityManager();
370 369
371 // Some updates are always disallowed. 370 // Some updates are always disallowed.
372 if ($this->getType() != $this->original->getType()) { 371 if ($this->getType() != $this->original->getType()) {
373 throw new FieldException("Cannot change the field type for an existing field storage."); 372 throw new FieldException("Cannot change the field type for an existing field storage.");
374 } 373 }
381 $module_handler->invokeAll('field_storage_config_update_forbid', [$this, $this->original]); 380 $module_handler->invokeAll('field_storage_config_update_forbid', [$this, $this->original]);
382 381
383 // Notify the entity manager. A listener can reject the definition 382 // Notify the entity manager. A listener can reject the definition
384 // update as invalid by raising an exception, which stops execution before 383 // update as invalid by raising an exception, which stops execution before
385 // the definition is written to config. 384 // the definition is written to config.
386 $entity_manager->onFieldStorageDefinitionUpdate($this, $this->original); 385 \Drupal::service('field_storage_definition.listener')->onFieldStorageDefinitionUpdate($this, $this->original);
387 } 386 }
388 387
389 /** 388 /**
390 * {@inheritdoc} 389 * {@inheritdoc}
391 */ 390 */
434 */ 433 */
435 public static function postDelete(EntityStorageInterface $storage, array $fields) { 434 public static function postDelete(EntityStorageInterface $storage, array $fields) {
436 // Notify the storage. 435 // Notify the storage.
437 foreach ($fields as $field) { 436 foreach ($fields as $field) {
438 if (!$field->deleted) { 437 if (!$field->deleted) {
439 \Drupal::entityManager()->onFieldStorageDefinitionDelete($field); 438 \Drupal::service('field_storage_definition.listener')->onFieldStorageDefinitionDelete($field);
440 $field->deleted = TRUE; 439 $field->deleted = TRUE;
441 } 440 }
442 } 441 }
443 // Unset static flag. 442 // Unset static flag.
444 static::$inDeletion = FALSE; 443 static::$inDeletion = FALSE;
487 /** 486 /**
488 * {@inheritdoc} 487 * {@inheritdoc}
489 */ 488 */
490 public function getColumns() { 489 public function getColumns() {
491 $schema = $this->getSchema(); 490 $schema = $this->getSchema();
492 // A typical use case for the method is to iterate on the columns, while
493 // some other use cases rely on identifying the first column with the key()
494 // function. Since the schema is persisted in the Field object, we take care
495 // of resetting the array pointer so that the former does not interfere with
496 // the latter.
497 reset($schema['columns']);
498 return $schema['columns']; 491 return $schema['columns'];
499 } 492 }
500 493
501 /** 494 /**
502 * {@inheritdoc} 495 * {@inheritdoc}