PostGroupBlock.php in Open Social 8.6
Same filename and directory in other branches
- 8.9 modules/social_features/social_post/src/Plugin/Block/PostGroupBlock.php
- 8 modules/social_features/social_post/src/Plugin/Block/PostGroupBlock.php
- 8.2 modules/social_features/social_post/src/Plugin/Block/PostGroupBlock.php
- 8.3 modules/social_features/social_post/src/Plugin/Block/PostGroupBlock.php
- 8.4 modules/social_features/social_post/src/Plugin/Block/PostGroupBlock.php
- 8.5 modules/social_features/social_post/src/Plugin/Block/PostGroupBlock.php
- 8.7 modules/social_features/social_post/src/Plugin/Block/PostGroupBlock.php
- 8.8 modules/social_features/social_post/src/Plugin/Block/PostGroupBlock.php
- 10.3.x modules/social_features/social_post/src/Plugin/Block/PostGroupBlock.php
- 10.0.x modules/social_features/social_post/src/Plugin/Block/PostGroupBlock.php
- 10.1.x modules/social_features/social_post/src/Plugin/Block/PostGroupBlock.php
- 10.2.x modules/social_features/social_post/src/Plugin/Block/PostGroupBlock.php
Namespace
Drupal\social_post\Plugin\BlockFile
modules/social_features/social_post/src/Plugin/Block/PostGroupBlock.phpView source
<?php
namespace Drupal\social_post\Plugin\Block;
use Drupal\Core\Extension\ModuleHandler;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Access\AccessResult;
/**
* Provides a 'PostGroupBlock' block.
*
* @Block(
* id = "post_group_block",
* admin_label = @Translation("Post on group block"),
* )
*/
class PostGroupBlock extends PostBlock {
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, $entityTypeManager, $currentUser, $formBuilder, ModuleHandler $moduleHandler) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $entityTypeManager, $currentUser, $formBuilder, $moduleHandler);
$this->entityType = 'post';
$this->bundle = 'post';
$this->formDisplay = 'group';
}
/**
* {@inheritdoc}
*/
protected function blockAccess(AccountInterface $account) {
$group = _social_group_get_current_group();
if (is_object($group)) {
if ($group
->hasPermission('add post entities in group', $account) && $account
->hasPermission("add post entities")) {
$membership = $group
->getMember($account);
$context = [];
if (!empty($membership)) {
$group_content = $membership
->getGroupContent();
$context = [
'group_content' => $group_content,
];
}
return \Drupal::entityTypeManager()
->getAccessControlHandler($this->entityType)
->createAccess($this->bundle, $account, $context, TRUE);
}
}
// By default, the block is not visible.
return AccessResult::forbidden()
->setCacheMaxAge(0);
}
}
Classes
Name | Description |
---|---|
PostGroupBlock | Provides a 'PostGroupBlock' block. |