From 713352d086577ff4013772e6b950b1a9a32d037d Mon Sep 17 00:00:00 2001 From: Denis Kolmerschlag Date: Tue, 17 Dec 2024 15:40:00 +0100 Subject: [PATCH] Fixes --- .../src/Service/ActivityLoggerFactory.php | 7 +++-- .../entity_access_by_field.module | 17 +++++++---- .../src/GraphQL/DecoratableTypeResolver.php | 2 +- .../GraphQL/DataProducer/MediaBridge.php | 4 +-- .../src/Kernel/SocialGraphQLTestBase.php | 30 +++++++++---------- .../social_album/social_album.module | 6 +++- .../src/Kernel/GraphQL/QueryEventTest.php | 2 +- .../social_group/social_group.module | 4 +++ phpstan.neon | 6 ++-- src/Installer/OptionalModuleManager.php | 2 +- 10 files changed, 47 insertions(+), 33 deletions(-) diff --git a/modules/custom/activity_logger/src/Service/ActivityLoggerFactory.php b/modules/custom/activity_logger/src/Service/ActivityLoggerFactory.php index e9720b67c99..31ea666b3c2 100644 --- a/modules/custom/activity_logger/src/Service/ActivityLoggerFactory.php +++ b/modules/custom/activity_logger/src/Service/ActivityLoggerFactory.php @@ -197,18 +197,19 @@ public function getMessageTypes(string $action, EntityBase $entity): array { continue; } - if ($this->activityEntityConditionManager->hasDefinition($mt_entity_condition)) { + if ($this->activityEntityConditionManager->hasDefinition($mt_entity_condition) === FALSE) { continue; } /** @var \Drupal\activity_creator\Plugin\ActivityEntityConditionInterface $context_plugin */ - $context_plugin = $this->activityContextManager->createInstance($mt_context); + $context_plugin = $this->activityEntityConditionManager->createInstance($mt_entity_condition); /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */ if (!$context_plugin->isValidEntityCondition($entity)) { continue; } - /** @var \Drupal\activity_creator\Plugin\ActivityContextInterface $context_plugin */ + /** @var \Drupal\activity_basics\Plugin\ActivityContext\ContentInMyGroupActivityContext $context_plugin */ + $context_plugin = $this->activityContextManager->createInstance($mt_context); if ($context_plugin->isValidEntity($entity)) { $message_types[$key] = [ 'messagetype' => $message_type, diff --git a/modules/custom/entity_access_by_field/entity_access_by_field.module b/modules/custom/entity_access_by_field/entity_access_by_field.module index 70000b90f1f..47776577aca 100644 --- a/modules/custom/entity_access_by_field/entity_access_by_field.module +++ b/modules/custom/entity_access_by_field/entity_access_by_field.module @@ -215,18 +215,23 @@ function entity_access_by_field_field_formatter_info_alter(array &$info): void { * Implements hook_ENTITY_TYPE_presave(). */ function entity_access_by_field_node_presave(NodeInterface $node): void { - // $original = $node->original; - $original = \Drupal::entityTypeManager() - ->getStorage('node') - ->loadUnchanged($node->id()); + $original = NULL; + if ($node->isNew() === FALSE) { + $original = \Drupal::entityTypeManager() + ->getStorage('node') + ->loadUnchanged($node->id()); + } // Get the field definitions of the node. $field_definitions = $node->getFieldDefinitions(); /** @var \Drupal\Core\Field\FieldConfigInterface $field_definition */ foreach ($field_definitions as $field_name => $field_definition) { - // Lets add a node access realm if the field is implemented. + // Let's add a node access realm if the field is implemented. if ($field_definition->getType() === 'entity_access_field') { - if (isset($node->status) && isset($original->status) && $node->status->value != $original->status->value) { + if ( + isset($node->status, $original->status) + && $node->status->value !== $original->status->value + ) { // Invalidate cache tags. Cache::invalidateTags(['activity_list']); } diff --git a/modules/custom/social_graphql/src/GraphQL/DecoratableTypeResolver.php b/modules/custom/social_graphql/src/GraphQL/DecoratableTypeResolver.php index 71448186d96..98d8df0ac39 100644 --- a/modules/custom/social_graphql/src/GraphQL/DecoratableTypeResolver.php +++ b/modules/custom/social_graphql/src/GraphQL/DecoratableTypeResolver.php @@ -89,7 +89,7 @@ public function __invoke($object) : string { } $klass = get_class($object); - throw new \RuntimeException("Can not map instance of '${klass}' to concrete GraphQL Type."); + throw new \RuntimeException("Can not map instance of '{$klass}' to concrete GraphQL Type."); } } diff --git a/modules/custom/social_graphql/src/Plugin/GraphQL/DataProducer/MediaBridge.php b/modules/custom/social_graphql/src/Plugin/GraphQL/DataProducer/MediaBridge.php index 8da8f556c6e..768c62a102f 100644 --- a/modules/custom/social_graphql/src/Plugin/GraphQL/DataProducer/MediaBridge.php +++ b/modules/custom/social_graphql/src/Plugin/GraphQL/DataProducer/MediaBridge.php @@ -169,7 +169,7 @@ protected function resolveFileItem(FileItem $file, $field) { return $file->get('alt')->getString(); default: - throw new \RuntimeException("Unsupported field for FileItem: '${field}'."); + throw new \RuntimeException("Unsupported field for FileItem: '{$field}'."); } } @@ -201,7 +201,7 @@ protected function resolveMediaEntity(MediaInterface $value, $field) { return $this->resolveFileItem($source_field, $field); default: - throw new \RuntimeException("Unsupported field for Media entity: '${field}'."); + throw new \RuntimeException("Unsupported field for Media entity: '{$field}'."); } } diff --git a/modules/custom/social_graphql/tests/src/Kernel/SocialGraphQLTestBase.php b/modules/custom/social_graphql/tests/src/Kernel/SocialGraphQLTestBase.php index c9eee261cda..ccfbc91b394 100644 --- a/modules/custom/social_graphql/tests/src/Kernel/SocialGraphQLTestBase.php +++ b/modules/custom/social_graphql/tests/src/Kernel/SocialGraphQLTestBase.php @@ -149,15 +149,15 @@ protected function assertPaginationPage(string $field, string $side, ?bool $reve $count = count($first_page); // Construct the filter as a string. We do this instead of variables since // it makes our function signature a bit easier. - $filter = "${side}: ${count}"; + $filter = "{$side}: {$count}"; if ($reverse) { $filter .= ", reverse: true"; } if ($cursor) { - $filter .= ", ${cursor}"; + $filter .= ", {$cursor}"; } if ($sortKey) { - $filter .= ", sortKey: ${sortKey}"; + $filter .= ", sortKey: {$sortKey}"; } // Create a query for the filter under test. Include some data that allow @@ -166,8 +166,8 @@ protected function assertPaginationPage(string $field, string $side, ?bool $reve $close_path = empty($parents) ? "" : " } " . implode("}", array_map(static fn () => "", $parents)); $query = " query { - ${open_path} - ${field}(${filter}) { + {$open_path} + {$field}({$filter}) { pageInfo { hasPreviousPage hasNextPage @@ -184,7 +184,7 @@ protected function assertPaginationPage(string $field, string $side, ?bool $reve } } } - ${close_path} + {$close_path} } "; @@ -209,12 +209,12 @@ protected function assertPaginationPage(string $field, string $side, ?bool $reve // Matching to an empty array causes a diff to show more information to // developers than simply an assertEmpty check. - self::assertEquals([], $executionResult->errors, "Errors for ${open_path}${field}(${filter})${close_path}"); - self::assertNotNull($executionResult->data, "No data for ${open_path}${field}(${filter})${close_path}"); + self::assertEquals([], $executionResult->errors, "Errors for {$open_path}{$field}({$filter}){$close_path}"); + self::assertNotNull($executionResult->data, "No data for {$open_path}{$field}({$filter}){$close_path}"); $parent_fields = array_map(static fn ($f) => explode('(', $f)[0], $parents); $data = NestedArray::getValue($executionResult->data, [...$parent_fields, $field]); - self::assertNotNull($data, "No data for ${open_path}${field}(${filter})${close_path}"); + self::assertNotNull($data, "No data for {$open_path}{$field}({$filter}){$close_path}"); $startCursor = $data['edges'][0]['cursor']; $endCursor = $data['edges'][count($first_page) - 1]['cursor']; @@ -226,16 +226,16 @@ protected function assertPaginationPage(string $field, string $side, ?bool $reve 'endCursor' => $endCursor, ]; - self::assertNotEquals(NULL, $data['pageInfo']['startCursor'], "Missing startCursor for ${field}(${filter})"); - self::assertNotEquals(NULL, $data['pageInfo']['endCursor'], "Missing endCursor for ${field}(${filter})"); - self::assertEquals($expected_page_info, $data['pageInfo'], "Incorrect pageInfo for ${field}(${filter})"); + self::assertNotEquals(NULL, $data['pageInfo']['startCursor'], "Missing startCursor for {$field}({$filter})"); + self::assertNotEquals(NULL, $data['pageInfo']['endCursor'], "Missing endCursor for {$field}({$filter})"); + self::assertEquals($expected_page_info, $data['pageInfo'], "Incorrect pageInfo for {$field}({$filter})"); $expected_nodes = array_map( static fn ($uuid) => ['id' => $uuid], $first_page ); - self::assertEquals($expected_nodes, $data['nodes'], "Incorrect nodes for ${field}(${filter})"); + self::assertEquals($expected_nodes, $data['nodes'], "Incorrect nodes for {$field}({$filter})"); // The cursor is ignored as it's an implementation detail and we have no // good way of predicting its value for comparison. It's usefulness is @@ -255,11 +255,11 @@ static function ($edge) { $data['edges'] ); - self::assertEquals($expected_edge_data, $actual_edge_data, "Incorrect edges for ${field}(${filter}) (cursors omitted from check)"); + self::assertEquals($expected_edge_data, $actual_edge_data, "Incorrect edges for {$field}({$filter}) (cursors omitted from check)"); // If we've been given a second page then we can test with a cursor. if (!empty($second_page)) { - $cursor = $side === 'first' ? "after: \"${endCursor}\"" : "before: \"${startCursor}\""; + $cursor = $side === 'first' ? "after: \"{$endCursor}\"" : "before: \"{$startCursor}\""; $this->assertPaginationPage( $field, $side, diff --git a/modules/social_features/social_album/social_album.module b/modules/social_features/social_album/social_album.module index 43442351c01..2c17e8902cb 100644 --- a/modules/social_features/social_album/social_album.module +++ b/modules/social_features/social_album/social_album.module @@ -428,7 +428,11 @@ function social_album_form_node_album_form_alter(array &$form, FormStateInterfac /** * Implements hook_field_group_form_process_alter(). */ -function social_album_field_group_form_process_alter(array &$element, GroupInterface $group, array &$complete_form): void { +function social_album_field_group_form_process_alter(array &$element, mixed $group, array &$complete_form): void { + if (!$group instanceof GroupInterface) { + return; + } + if ($group->get('group_name')->getValue() === 'group_album_settings') { $element['#states'] = [ 'visible' => [ diff --git a/modules/social_features/social_event/tests/src/Kernel/GraphQL/QueryEventTest.php b/modules/social_features/social_event/tests/src/Kernel/GraphQL/QueryEventTest.php index 4d4b7cc4094..2f9df2dfe00 100644 --- a/modules/social_features/social_event/tests/src/Kernel/GraphQL/QueryEventTest.php +++ b/modules/social_features/social_event/tests/src/Kernel/GraphQL/QueryEventTest.php @@ -220,7 +220,7 @@ public function testSupportsFieldsIncludedInModule() : void { /** * Test that it respects the access events permission. */ - public function testRequiresAccessEventsPermission() { + public function testRequiresAccessEventsPermission(): void { $topic = $this->createNode([ 'type' => 'event', 'field_content_visibility' => 'public', diff --git a/modules/social_features/social_group/social_group.module b/modules/social_features/social_group/social_group.module index cfaa0ca3684..1a3c66fcff2 100644 --- a/modules/social_features/social_group/social_group.module +++ b/modules/social_features/social_group/social_group.module @@ -2081,6 +2081,10 @@ function social_group_get_allowed_visibility_options_per_group_type(string|NULL $group = _social_group_get_current_group($entity); } + if ($group === NULL) { + return []; + } + if ($group->hasField('field_group_allowed_visibility')) { $visibility_options['public'] = FALSE; $visibility_options['community'] = FALSE; diff --git a/phpstan.neon b/phpstan.neon index 562f741e50e..5acbf40af0d 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -75,9 +75,9 @@ parameters: - '#Access to an undefined property Drupal\\file\\FileInterface::\$download\.#' - '#Parameter \$item of static method Drupal\\social_eda\\Types\\Address::fromFieldItem\(\) expects Drupal\\address\\Plugin\\Field\\FieldType\\AddressItem\|null, Drupal\\Core\\Field\\FieldItemInterface\|null given.#' ## Extend things from OS product. -# - '#Class Drupal\\social_eda_dispatcher\\Dispatcher not found.#' - - '#.*CloudEvents\\V1\\CloudEvent.*#' - - '#.*CloudEvents\\CloudEventInterface.*#' + - '#Class Drupal\\social_eda_dispatcher\\Dispatcher not found.#' +# - '#.*CloudEvents\\V1\\CloudEvent.*#' +# - '#.*CloudEvents\\CloudEventInterface.*#' ## Need to create services for that.a - '#Not allowed to call private function _activity_basics_entity_action from module social_follow_tag#' - '#Not allowed to call private function _activity_send_email_default_template_items from module social_swiftmail#' diff --git a/src/Installer/OptionalModuleManager.php b/src/Installer/OptionalModuleManager.php index 9e725dc1c42..10c56f03f19 100644 --- a/src/Installer/OptionalModuleManager.php +++ b/src/Installer/OptionalModuleManager.php @@ -118,7 +118,7 @@ protected function getInstallProfileFeatureDefinitions() : array { $contents = file_get_contents($feature_list_file); if ($contents === FALSE) { - throw new IOException("Could not read '${feature_list_file}'."); + throw new IOException("Could not read '{$feature_list_file}'."); } $features = Yaml::decode($contents);