Use a link mode for space button "Join" from space header (#5150)

This commit is contained in:
Yuriy Bakhtin 2021-07-01 12:06:54 +03:00 committed by GitHub
parent 09b1dd060f
commit 59dfc9c2a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 3 deletions

View File

@ -4,6 +4,7 @@
- Fix #5128: Prerequisites: Increase PHP Min version to 7.3
- Fix #5136: Fix get value of user profile fields with types "Checkbox List" and "Checkbox"
- Fix #5137: Fix convert to short integer on PHP 8
- Fix #5149: Use a link mode for space button "Join" from space header
1.9.0-beta.1 (June 15, 2021)

View File

@ -47,6 +47,8 @@ class MembershipButton extends Widget
],
'becomeMember' => [
'title' => Yii::t('SpaceModule.base', 'Join'),
'mode' => 'ajax', // 'ajax' - to use data-action-* options for AJAX request, 'link' - to use button as simple <a> link
'url' => '#',
'attrs' => [
'data-action-click' => 'content.container.relationship',
'data-action-url' => $this->space->createUrl('/space/membership/request-membership'),
@ -128,10 +130,20 @@ class MembershipButton extends Widget
*/
public function run()
{
$options = $this->getOptions();
if ($options['becomeMember']['mode'] == 'link') {
// Switch button "Join" to link mode
$options['becomeMember']['url'] = $options['becomeMember']['attrs']['data-action-url'];
$options['becomeMember']['attrs']['data-method'] = 'POST';
unset($options['becomeMember']['attrs']['data-action-click']);
unset($options['becomeMember']['attrs']['data-action-url']);
}
return $this->render('membershipButton', [
'space' => $this->space,
'membership' => $this->space->getMembership(),
'options' => $this->getOptions(),
'options' => $options,
'canCancelMembership' => !$this->space->isSpaceOwner() && $this->space->canLeave(),
]);
}

View File

@ -14,7 +14,7 @@ if ($membership === null) {
if ($space->join_policy == Space::JOIN_POLICY_APPLICATION) {
echo Html::a($options['requestMembership']['title'], $options['requestMembership']['url'], $options['requestMembership']['attrs']);
} else {
echo Html::a($options['becomeMember']['title'], '#', $options['becomeMember']['attrs']);
echo Html::a($options['becomeMember']['title'], $options['becomeMember']['url'], $options['becomeMember']['attrs']);
}
}
} elseif ($membership->status == Membership::STATUS_INVITED) {

View File

@ -21,7 +21,10 @@ use humhub\modules\space\widgets\MembershipButton;
<div class="controls controls-header pull-right">
<?= HeaderControls::widget(['widgets' => [
[InviteButton::class, ['space' => $container], ['sortOrder' => 10]],
[MembershipButton::class, ['space' => $container], ['sortOrder' => 20]],
[MembershipButton::class, [
'space' => $container,
'options' => ['becomeMember' => ['mode' => 'link']],
], ['sortOrder' => 20]],
[FollowButton::class, [
'space' => $container,
'followOptions' => ['class' => 'btn btn-primary'],