Skip to content
Snippets Groups Projects
Commit 86789872 authored by Luhur Abdi Rizal's avatar Luhur Abdi Rizal
Browse files

Issue #3387995 by el7cosmos, lamp5: TypeError:...

Issue #3387995 by el7cosmos, lamp5: TypeError: core_event_dispatcher_entity_create_access(): Argument #3 ($entityBundle) must be of type ?string, int given when entity bundle machine namie is number
parent e7df9d43
No related branches found
Tags 4.0.1
No related merge requests found
<?php
declare(strict_types=1);
namespace Drupal\core_event_dispatcher\Event\Entity;
use Drupal\Component\EventDispatcher\Event;
......@@ -15,8 +17,7 @@ abstract class EntityBundleEventBase extends Event implements EventInterface {
* @param string $bundle
* The name of the bundle.
*/
public function __construct(protected readonly string $entity_type_id, protected readonly string $bundle) {
}
public function __construct(protected readonly string $entity_type_id, protected readonly string|int $bundle) {}
/**
* Gets the type of the entity.
......@@ -33,7 +34,7 @@ abstract class EntityBundleEventBase extends Event implements EventInterface {
* @return string
*/
public function getBundle(): string {
return $this->bundle;
return (string) $this->bundle;
}
}
<?php
declare(strict_types=1);
namespace Drupal\core_event_dispatcher\Event\Entity;
use Drupal\Component\EventDispatcher\Event;
......@@ -35,7 +37,7 @@ final class EntityCreateAccessEvent extends Event implements EventInterface, Eve
* @param string|null $entityBundle
* The entity bundle name.
*/
public function __construct(AccountInterface $account, protected readonly array $context, protected readonly ?string $entityBundle = NULL) {
public function __construct(AccountInterface $account, protected readonly array $context, protected readonly string|int|null $entityBundle = NULL) {
$this->account = $account;
}
......@@ -56,7 +58,7 @@ final class EntityCreateAccessEvent extends Event implements EventInterface, Eve
* The entity bundle name.
*/
public function getEntityBundle(): ?string {
return $this->entityBundle;
return $this->entityBundle ? (string) $this->entityBundle : NULL;
}
/**
......
......@@ -36,7 +36,7 @@ class EntityCreateAccessEventTest extends KernelTestBase {
*
* @var \Drupal\Core\Access\AccessResultInterface
*/
protected $accessResult;
protected AccessResultInterface $accessResult;
/**
* Test EntityCreateAccessEvent.
......@@ -83,4 +83,20 @@ class EntityCreateAccessEventTest extends KernelTestBase {
];
}
/**
* Test EntityCreateAccessEvent for integer bundle.
*
* @throws \Exception
*/
public function testEntityCreateAccessEventIntegerBundle(): void {
$bundle = mt_rand();
entity_test_create_bundle($bundle);
$accessControlHandler = $this->container->get('entity_type.manager')->getAccessControlHandler('entity_test');
$context = [
'test' => TRUE,
];
$this->assertFalse($accessControlHandler->createAccess($bundle, NULL, $context));
}
}
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