Skip to content
Snippets Groups Projects
Verified Commit 9c865d11 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3440039 by samit.310@gmail.com, quietone, smustgrave, catch, mondrake:...

Issue #3440039 by samit.310@gmail.com, quietone, smustgrave, catch, mondrake: Log warning when relatable resource type references a missing entity type / bundle instead triggering E_USER_WARNING

(cherry picked from commit bcf45f5d)
parent fea64b66
No related branches found
No related tags found
22 merge requests!11185Issue #3477324 by andypost, alexpott: Fix usage of str_getcsv() and fgetcsv() for PHP 8.4,!10602Issue #3438769 by vinmayiswamy, antonnavi, michelle, amateescu: Sub workspace does not clear,!10301Issue #3469309 by mstrelan, smustgrave, moshe weitzman: Use one-time login...,!10187Issue #3487488 by dakwamine: ExtensionMimeTypeGuesser::guessMimeType must support file names with "0" (zero) like foo.0.zip,!9944Issue #3483353: Consider making the createCopy config action optionally fail...,!9929Issue #3445469 by pooja_sharma, smustgrave: Add additional test coverage for...,!9787Resolve issue 3479427 - bootstrap barrio issue under Windows,!9742Issue #3463908 by catch, quietone: Split OptionsFieldUiTest into two,!9526Issue #3458177 by mondrake, catch, quietone, godotislate, longwave, larowlan,...,!8738Issue #3424162 by camilledavis, dineshkumarbollu, smustgrave: Claro...,!8704Make greek characters available in ckeditor5,!8597Draft: Issue #3442259 by catch, quietone, dww: Reduce time of Migrate Upgrade tests...,!8533Issue #3446962 by kim.pepper: Remove incorrectly added...,!8517Issue #3443748 by NexusNovaz, smustgrave: Testcase creates false positive,!8325Update file Sort.php,!8095Expose document root on install,!7930Resolve #3427374 "Taxonomytid viewsargumentdefault plugin",!7627Issue #3439440 by nicxvan, Binoli Lalani, longwave: Remove country support from DateFormatter,!7445Issue #3440169: When using drupalGet(), provide an associative array for $headers,!6502Draft: Resolve #2938524 "Plach testing issue",!38582585169-10.1.x,!3226Issue #2987537: Custom menu link entity type should not declare "bundle" entity key
Pipeline #147421 passed with warnings
Pipeline: drupal

#147429

    Pipeline: drupal

    #147424

      ......@@ -16,6 +16,7 @@
      use Drupal\Core\Field\FieldDefinitionInterface;
      use Drupal\Core\Installer\InstallerKernel;
      use Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItemInterface;
      use Drupal\Core\Logger\LoggerChannelTrait;
      use Drupal\Core\TypedData\DataReferenceTargetDefinition;
      use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
      use Symfony\Component\HttpKernel\Exception\PreconditionFailedHttpException;
      ......@@ -42,6 +43,8 @@
      */
      class ResourceTypeRepository implements ResourceTypeRepositoryInterface {
      use LoggerChannelTrait;
      /**
      * The entity type manager.
      *
      ......@@ -467,16 +470,15 @@ protected function getRelatableResourceTypesFromFieldDefinition(FieldDefinitionI
      // is not guaranteed during this period and may cause confusing and
      // unnecessary warnings.
      if (!InstallerKernel::installationAttempted()) {
      trigger_error(
      sprintf(
      'The "%s" at "%s:%s" references the "%s:%s" entity type that does not exist.',
      $field_definition->getName(),
      $field_definition->getTargetEntityTypeId(),
      $field_definition->getTargetBundle(),
      $entity_type_id,
      $target_bundle
      ),
      E_USER_WARNING
      $this->getLogger('jsonapi')->warning(
      'The "@name" at "@target_entity_type_id:@target_bundle" references the "@entity_type_id:@bundle" entity type that does not exist.',
      [
      '@name' => $field_definition->getName(),
      '@target_entity_type_id' => $field_definition->getTargetEntityTypeId(),
      '@target_bundle' => $field_definition->getTargetBundle(),
      '@entity_type_id' => $entity_type_id,
      '@bundle' => $target_bundle,
      ],
      );
      }
      }
      ......
      ......@@ -4,9 +4,9 @@
      namespace Drupal\Tests\jsonapi\Kernel\ResourceType;
      use Drupal\Core\Database\Database;
      use Drupal\Tests\jsonapi\Kernel\JsonapiKernelTestBase;
      use Drupal\node\Entity\NodeType;
      use PHPUnit\Framework\Error\Warning;
      /**
      * @coversDefaultClass \Drupal\jsonapi\ResourceType\ResourceType
      ......@@ -28,6 +28,7 @@ class RelatedResourceTypesTest extends JsonapiKernelTestBase {
      'system',
      'user',
      'field',
      'dblog',
      ];
      /**
      ......@@ -63,6 +64,7 @@ protected function setUp(): void {
      // Add the additional table schemas.
      $this->installSchema('node', ['node_access']);
      $this->installSchema('user', ['users_data']);
      $this->installSchema('dblog', ['watchdog']);
      NodeType::create([
      'type' => 'foo',
      ......@@ -202,17 +204,22 @@ public function testGetRelatableResourceTypesFromFieldDefinition() {
      ]);
      $fields = $field_config_storage->loadByProperties(['field_name' => 'field_ref_with_missing_bundle']);
      static::assertSame(['missing_bundle'], $fields['node.foo.field_ref_with_missing_bundle']->getItemDefinition()->getSetting('handler_settings')['target_bundles']);
      try {
      $this->resourceTypeRepository->get('node', 'foo')->getRelatableResourceTypesByField('field_ref_with_missing_bundle');
      static::fail('The above code must produce a warning since the "missing_bundle" does not exist.');
      }
      catch (Warning $e) {
      static::assertSame(
      'The "field_ref_with_missing_bundle" at "node:foo" references the "node:missing_bundle" entity type that does not exist.',
      $e->getMessage()
      );
      }
      $a = $this->resourceTypeRepository->get('node', 'foo')->getRelatableResourceTypesByField('field_ref_with_missing_bundle');
      static::assertSame(['missing_bundle'], $fields['node.foo.field_ref_with_missing_bundle']->getItemDefinition()->getSetting('handler_settings')['target_bundles']);
      $arguments = [
      '@name' => 'field_ref_with_missing_bundle',
      '@target_entity_type_id' => 'node',
      '@target_bundle' => 'foo',
      '@entity_type_id' => 'node',
      '@bundle' => 'missing_bundle',
      ];
      $logged = Database::getConnection()->select('watchdog')
      ->fields('watchdog', ['variables'])
      ->condition('type', 'jsonapi')
      ->condition('message', 'The "@name" at "@target_entity_type_id:@target_bundle" references the "@entity_type_id:@bundle" entity type that does not exist.')
      ->execute()
      ->fetchField();
      $this->assertEquals(serialize($arguments), $logged);
      }
      /**
      ......
      0% Loading or .
      You are about to add 0 people to the discussion. Proceed with caution.
      Finish editing this message first!
      Please register or to comment