GroupAddTopicBlock.php in Open Social 8
Same filename and directory in other branches
- 8.9 modules/social_features/social_group/src/Plugin/Block/GroupAddTopicBlock.php
- 8.2 modules/social_features/social_group/src/Plugin/Block/GroupAddTopicBlock.php
- 8.3 modules/social_features/social_group/src/Plugin/Block/GroupAddTopicBlock.php
- 8.4 modules/social_features/social_group/src/Plugin/Block/GroupAddTopicBlock.php
- 8.5 modules/social_features/social_group/src/Plugin/Block/GroupAddTopicBlock.php
- 8.6 modules/social_features/social_group/src/Plugin/Block/GroupAddTopicBlock.php
- 8.7 modules/social_features/social_group/src/Plugin/Block/GroupAddTopicBlock.php
- 8.8 modules/social_features/social_group/src/Plugin/Block/GroupAddTopicBlock.php
- 10.3.x modules/social_features/social_group/src/Plugin/Block/GroupAddTopicBlock.php
- 10.0.x modules/social_features/social_group/src/Plugin/Block/GroupAddTopicBlock.php
- 10.1.x modules/social_features/social_group/src/Plugin/Block/GroupAddTopicBlock.php
- 10.2.x modules/social_features/social_group/src/Plugin/Block/GroupAddTopicBlock.php
Namespace
Drupal\social_group\Plugin\BlockFile
modules/social_features/social_group/src/Plugin/Block/GroupAddTopicBlock.phpView source
<?php
namespace Drupal\social_group\Plugin\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Url;
use Drupal\Core\Link;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Access\AccessResult;
/**
* Provides a 'GroupAddTopicBlock' block.
*
* @Block(
* id = "group_add_topic_block",
* admin_label = @Translation("Group add topic block"),
* )
*/
class GroupAddTopicBlock extends BlockBase {
/**
* {@inheritdoc}
*
* Custom access logic to display the block.
*/
public function blockAccess(AccountInterface $account) {
$group = _social_group_get_current_group();
if (is_object($group)) {
if ($group
->hasPermission('create group_node:topic entity', $account)) {
if ($group
->getGroupType()
->id() === 'public_group') {
$config = \Drupal::config('entity_access_by_field.settings');
if ($config
->get('disable_public_visibility') === 1 && !$account
->hasPermission('override disabled public visibility')) {
return AccessResult::forbidden();
}
}
return AccessResult::allowed();
}
}
// By default, the block is not visible.
return AccessResult::forbidden();
}
/**
* {@inheritdoc}
*/
public function build() {
$build = [];
$group = _social_group_get_current_group();
if (is_object($group)) {
$url = Url::fromUserInput("/group/{$group->id()}/content/create/group_node:topic");
$link_options = [
'attributes' => [
'class' => [
'btn',
'btn-primary',
'btn-raised',
'waves-effect',
'brand-bg-primary',
],
],
];
$url
->setOptions($link_options);
$build['content'] = Link::fromTextAndUrl(t('Create Topic'), $url)
->toRenderable();
// Cache.
$build['#cache']['contexts'][] = 'url.path';
$build['#cache']['tags'][] = 'group:' . $group
->id();
}
return $build;
}
}
Classes
Name | Description |
---|---|
GroupAddTopicBlock | Provides a 'GroupAddTopicBlock' block. |