Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
denis-getopensocial committed Dec 17, 2024
1 parent 3932726 commit 713352d
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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}'.");
}
}

Expand Down Expand Up @@ -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}'.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -184,7 +184,7 @@ protected function assertPaginationPage(string $field, string $side, ?bool $reve
}
}
}
${close_path}
{$close_path}
}
";
Expand All @@ -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'];
Expand All @@ -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
Expand All @@ -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,
Expand Down
6 changes: 5 additions & 1 deletion modules/social_features/social_album/social_album.module
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
4 changes: 4 additions & 0 deletions modules/social_features/social_group/social_group.module
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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#'
Expand Down
2 changes: 1 addition & 1 deletion src/Installer/OptionalModuleManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 713352d

Please sign in to comment.