function FieldStorageCreateCheckSubscriber::onFieldStorageDefinitionCreateEvent

Listener method for any field storage definition create event.

Parameters

\Drupal\Core\Field\FieldStorageDefinitionEvent $event: The field storage definition event object.

string $event_name: The event name.

File

core/lib/Drupal/Core/Test/EventSubscriber/FieldStorageCreateCheckSubscriber.php, line 71

Class

FieldStorageCreateCheckSubscriber
Response subscriber to field storage events.

Namespace

Drupal\Core\Test\EventSubscriber

Code

public function onFieldStorageDefinitionCreateEvent(FieldStorageDefinitionEvent $event, $event_name) : void {
  $entity_type_id = $event->getFieldStorageDefinition()
    ->getTargetEntityTypeId();
  if ($entity_type_id) {
    $storage = $this->entityTypeManager
      ->getStorage($entity_type_id);
    if ($storage instanceof SqlEntityStorageInterface) {
      $base_table = $storage->getTableMapping()
        ->getBaseTable();
      if (!$this->schema
        ->tableExists($base_table)) {
        if ($this->throwLogicExceptionOrDeprecationWarning) {
          throw new \LogicException(sprintf('Creating the "%s" field storage definition without the entity schema "%s" being installed is not allowed.', $event->getFieldStorageDefinition()
            ->id(), $entity_type_id));
        }
        else {
          @trigger_error('Creating the "' . $event->getFieldStorageDefinition()
            ->id() . '" field storage definition without the entity schema "' . $entity_type_id . '" being installed is deprecated in drupal:11.2.0 and will be replaced by a LogicException in drupal:12.0.0. See https://www.drupal.org/node/3493981', E_USER_DEPRECATED);
        }
      }
    }
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.