Skip to content
This repository has been archived by the owner on Aug 18, 2024. It is now read-only.

472 Fixes #486

Merged
merged 7 commits into from
May 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 1 addition & 17 deletions og.module
Original file line number Diff line number Diff line change
Expand Up @@ -313,28 +313,12 @@ function og_theme($existing, $type, $theme, $path) {
'count' => 0,
'membership_states' => [],
'group' => NULL,
'group_label' => NULL,
],
],
];
}

/**
* Prepares variables for member count templates.
*
* Default template: og-member-count.html.twig.
*
* @param array $variables
* An associative array containing:
* - count: An integer representing the number of members in the group.
* - group: The group, which is a content entity.
*/
function template_preprocess_og_member_count(array &$variables) {
/** @var \Drupal\Core\Entity\ContentEntityInterface $group */
$group = $variables['group'];

$variables['group_label'] = $group->label();
}

/**
* Invalidates group content cache tags for the groups this entity belongs to.
*
Expand Down
3 changes: 2 additions & 1 deletion src/Plugin/Block/MemberCountBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function defaultConfiguration() {
return [
'count_blocked_users' => FALSE,
'count_pending_users' => FALSE,
];
] + parent::defaultConfiguration();
}

/**
Expand Down Expand Up @@ -138,6 +138,7 @@ public function build() {
'#theme' => 'og_member_count',
'#count' => count($membership_ids),
'#group' => $group,
'#group_label' => $group->label(),
'#membership_states' => $states,
];
}
Expand Down
1 change: 1 addition & 0 deletions templates/og-member-count.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Available variables:
* - count: The number of members in the group.
* - membership_states: An array of membership states included in the count.
* - group: The group, which is a content entity.
* - group_label: The group label.
*
* @see \Drupal\og\Plugin\Block\MemberCountBlock
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Kernel/Plugin/Block/MemberCountBlockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ protected function renderBlock($group_key) {
*/
protected function assertMemberCount($group_key, $expected_count) {
$expected_string = (string) $this->formatPlural($expected_count, '@label has 1 member.', '@label has @count members', ['@label' => $this->groups[$group_key]->label()]);
$this->assertTrue(strpos($this->renderBlock($group_key), $expected_string) !== FALSE);
$this->assertContains($expected_string, (string) $this->renderBlock($group_key));
}

/**
Expand Down