Skip to content
Snippets Groups Projects
Commit 7d233348 authored by Patrick Kenny's avatar Patrick Kenny
Browse files

Issue #3483586 by ptmkenny: Require PHP 8.3

parent 387b9470
Branches commev-alias
No related tags found
1 merge request!9Require PHP 8.3
Pipeline #321450 passed
......@@ -36,9 +36,11 @@ phpstan:
# Uncomment the lines below if you want to override any of the variables. The following is just an example.
################
variables:
CORE_PHP_MIN: "8.2"
# _TARGET_PHP: "8.3"
# SKIP_ESLINT: '1'
# OPT_IN_TEST_NEXT_MAJOR: '1'
OPT_IN_TEST_NEXT_MAJOR: '1'
OPT_IN_TEST_PREVIOUS_MAJOR: '1'
# CORE_PHP_MIN: "8.3"
# _CURL_TEMPLATES_REF: 'main'
composer (previous major):
variables:
PHP_VERSION: '8.3'
......@@ -3,7 +3,7 @@
"description": "Log JSON data in decoupled scenarios.",
"type": "drupal-module",
"require": {
"php": ">=8.2",
"php": ">=8.3",
"ext-json": "*",
"drupal/json_field": "^1.3"
},
......
......@@ -41,19 +41,17 @@ function template_preprocess_log_json(array &$variables): void {
* Implements hook_user_cancel().
*/
function decoupled_json_log_user_cancel(array $edit, UserInterface $account, string $method): void {
switch ($method) {
case 'user_cancel_reassign':
// Anonymize json logs.
$storage = \Drupal::entityTypeManager()->getStorage('log_json');
$log_json_ids = $storage->getQuery()
->condition('uid', $account->id())
->accessCheck(FALSE)
->execute();
foreach ($storage->loadMultiple($log_json_ids) as $log_json) {
/** @var \Drupal\decoupled_json_log\LogJsonInterface $log_json */
$log_json->setOwnerId(0)->save();
}
break;
if ($method === 'user_cancel_reassign') {
// Anonymize json logs.
$storage = \Drupal::entityTypeManager()->getStorage('log_json');
$log_json_ids = $storage->getQuery()
->condition('uid', $account->id())
->accessCheck(FALSE)
->execute();
foreach ($storage->loadMultiple($log_json_ids) as $log_json) {
/** @var \Drupal\decoupled_json_log\LogJsonInterface $log_json */
$log_json->setOwnerId(0)->save();
}
}
}
......
......@@ -71,6 +71,7 @@ final class LogJson extends ContentEntityBase implements LogJsonInterface {
/**
* {@inheritdoc}
*/
#[\Override]
public function preSave(EntityStorageInterface $storage): void {
parent::preSave($storage);
if ($this->getOwnerId() === NULL) {
......@@ -82,6 +83,7 @@ final class LogJson extends ContentEntityBase implements LogJsonInterface {
/**
* {@inheritdoc}
*/
#[\Override]
public static function baseFieldDefinitions(EntityTypeInterface $entity_type): array {
$fields = parent::baseFieldDefinitions($entity_type);
......
......@@ -15,6 +15,7 @@ final class LogJsonForm extends ContentEntityForm {
/**
* {@inheritdoc}
*/
#[\Override]
public function save(array $form, FormStateInterface $form_state): int {
$result = parent::save($form, $form_state);
......
......@@ -17,6 +17,7 @@ final class LogJsonTypeForm extends BundleEntityFormBase {
/**
* {@inheritdoc}
*/
#[\Override]
public function form(array $form, FormStateInterface $form_state): array {
$form = parent::form($form, $form_state);
......@@ -49,6 +50,7 @@ final class LogJsonTypeForm extends BundleEntityFormBase {
/**
* {@inheritdoc}
*/
#[\Override]
protected function actions(array $form, FormStateInterface $form_state): array {
$actions = parent::actions($form, $form_state);
$actions['submit']['#value'] = $this->t('Save json log type');
......@@ -59,6 +61,7 @@ final class LogJsonTypeForm extends BundleEntityFormBase {
/**
* {@inheritdoc}
*/
#[\Override]
public function save(array $form, FormStateInterface $form_state): int {
$result = parent::save($form, $form_state);
......
......@@ -15,6 +15,7 @@ class SettingsForm extends ConfigFormBase {
/**
* {@inheritdoc}
*/
#[\Override]
public function getFormId(): string {
return 'decoupled_json_log_settings_form';
}
......@@ -22,6 +23,7 @@ class SettingsForm extends ConfigFormBase {
/**
* {@inheritdoc}
*/
#[\Override]
public function buildForm(array $form, FormStateInterface $form_state): array {
$form = parent::buildForm($form, $form_state);
$config = $this->config('decoupled_json_log.settings');
......@@ -55,6 +57,7 @@ class SettingsForm extends ConfigFormBase {
/**
* {@inheritdoc}
*/
#[\Override]
public function submitForm(array &$form, FormStateInterface $form_state): void {
$rate_limit = [
'count_anon' => $form_state->getValue('count_anon'),
......@@ -72,6 +75,7 @@ class SettingsForm extends ConfigFormBase {
/**
* {@inheritdoc}
*/
#[\Override]
protected function getEditableConfigNames(): array {
return [
'decoupled_json_log.settings',
......
......@@ -21,6 +21,7 @@ final class LogJsonAccessControlHandler extends EntityAccessControlHandler {
/**
* {@inheritdoc}
*/
#[\Override]
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account): AccessResult {
return match($operation) {
'view' => AccessResult::allowedIfHasPermissions($account, ['view log_json', 'administer log_json types'], 'OR'),
......@@ -33,6 +34,7 @@ final class LogJsonAccessControlHandler extends EntityAccessControlHandler {
/**
* {@inheritdoc}
*/
#[\Override]
protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL): AccessResult {
return AccessResult::allowedIfHasPermissions($account, ['create log_json', 'administer log_json types'], 'OR');
}
......
......@@ -15,6 +15,7 @@ final class LogJsonListBuilder extends EntityListBuilder {
/**
* {@inheritdoc}
*/
#[\Override]
public function buildHeader(): array {
$header = [];
$header['id'] = $this->t('ID');
......@@ -27,6 +28,7 @@ final class LogJsonListBuilder extends EntityListBuilder {
/**
* {@inheritdoc}
*/
#[\Override]
public function buildRow(EntityInterface $entity): array {
$row = [];
/** @var \Drupal\decoupled_json_log\LogJsonInterface $entity */
......
......@@ -18,6 +18,7 @@ final class LogJsonTypeListBuilder extends ConfigEntityListBuilder {
/**
* {@inheritdoc}
*/
#[\Override]
public function buildHeader(): array {
$header = [];
$header['label'] = $this->t('Label');
......@@ -27,6 +28,7 @@ final class LogJsonTypeListBuilder extends ConfigEntityListBuilder {
/**
* {@inheritdoc}
*/
#[\Override]
public function buildRow(EntityInterface $entity): array {
$row = [];
$row['label'] = $entity->label();
......@@ -36,6 +38,7 @@ final class LogJsonTypeListBuilder extends ConfigEntityListBuilder {
/**
* {@inheritdoc}
*/
#[\Override]
public function render(): array {
$build = parent::render();
......
......@@ -21,58 +21,20 @@ use Webmozart\Assert\Assert;
*/
final class RateLimitPerUserValidator extends ConstraintValidator implements ContainerInjectionInterface {
/**
* The current user account.
*
* @var \Drupal\Core\Session\AccountInterface
*/
protected AccountInterface $currentUser;
/**
* The entity type manager interface.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected EntityTypeManagerInterface $entityTypeManager;
/**
* The time service.
*
* @var \Drupal\Component\Datetime\TimeInterface
*/
protected TimeInterface $time;
/**
* The config factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected ConfigFactoryInterface $configFactory;
/**
* Constructs RateLimitPerUserValidator.
*
* @param \Drupal\Core\Session\AccountInterface $current_user
* The current user.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager service.
* @param \Drupal\Component\Datetime\TimeInterface $time
* The time service.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory.
*/
public function __construct(AccountInterface $current_user, EntityTypeManagerInterface $entity_type_manager, TimeInterface $time, ConfigFactoryInterface $config_factory) {
$this->currentUser = $current_user;
$this->entityTypeManager = $entity_type_manager;
$this->time = $time;
$this->configFactory = $config_factory;
public function __construct(
protected AccountInterface $currentUser,
protected EntityTypeManagerInterface $entityTypeManager,
protected TimeInterface $time,
protected ConfigFactoryInterface $configFactory,
) {
}
/**
* {@inheritdoc}
*/
#[\Override]
public static function create(ContainerInterface $container): static {
return new static(
return new self(
$container->get('current_user'),
$container->get('entity_type.manager'),
$container->get('datetime.time'),
......@@ -83,6 +45,7 @@ final class RateLimitPerUserValidator extends ConstraintValidator implements Con
/**
* {@inheritdoc}
*/
#[\Override]
public function validate(mixed $value, Constraint $constraint): void {
if (is_object($value)) {
if (method_exists($value, 'label')) {
......@@ -91,14 +54,12 @@ final class RateLimitPerUserValidator extends ConstraintValidator implements Con
else {
throw new DecoupledJsonLogException('Value does not have label() method!');
}
if ($value instanceof LogJsonInterface && is_string($name)) {
if (!$this->isPostCountBelowLimit()) {
if ($constraint instanceof RateLimitPerUser) {
$this->context->addViolation($constraint->postIntervalExceeded, ['%value' => $value->label()]);
}
else {
throw new DecoupledJsonLogException('Failed to set constraint RateLimitPerUser!');
}
if ($value instanceof LogJsonInterface && is_string($name) && !$this->isPostCountBelowLimit()) {
if ($constraint instanceof RateLimitPerUser) {
$this->context->addViolation($constraint->postIntervalExceeded, ['%value' => $value->label()]);
}
else {
throw new DecoupledJsonLogException('Failed to set constraint RateLimitPerUser!');
}
}
}
......
......@@ -17,7 +17,7 @@ class DecoupledJsonLogLimitingRouteSubscriber extends RouteSubscriberBase {
/**
* The machine name of entities created by this module.
*/
private const ENTITY_MACHINE_NAME = 'log_json';
private const string ENTITY_MACHINE_NAME = 'log_json';
/**
* {@inheritdoc}
......@@ -25,6 +25,7 @@ class DecoupledJsonLogLimitingRouteSubscriber extends RouteSubscriberBase {
* For details, see
* https://www.drupal.org/docs/core-modules-and-themes/core-modules/jsonapi-module/security-considerations#s-6-limit-which-entity-bundles-may-be-created-or-editedby-removing-some-routes.
*/
#[\Override]
protected function alterRoutes(RouteCollection $collection): void {
foreach ($collection as $name => $route) {
$defaults = $route->getDefaults();
......
......@@ -11,7 +11,7 @@ use Drupal\KernelTests\KernelTestBase;
*/
class DecoupledJsonLogInstallTest extends KernelTestBase {
private const MODULE_NAME = 'decoupled_json_log';
private const string MODULE_NAME = 'decoupled_json_log';
/**
* Test that the module can be installed and uninstalled.
......
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