GroupHeroBlock.php in Open Social 8.8
Same filename and directory in other branches
- 8.9 modules/social_features/social_group/src/Plugin/Block/GroupHeroBlock.php
- 8 modules/social_features/social_group/src/Plugin/Block/GroupHeroBlock.php
- 8.2 modules/social_features/social_group/src/Plugin/Block/GroupHeroBlock.php
- 8.3 modules/social_features/social_group/src/Plugin/Block/GroupHeroBlock.php
- 8.4 modules/social_features/social_group/src/Plugin/Block/GroupHeroBlock.php
- 8.5 modules/social_features/social_group/src/Plugin/Block/GroupHeroBlock.php
- 8.6 modules/social_features/social_group/src/Plugin/Block/GroupHeroBlock.php
- 8.7 modules/social_features/social_group/src/Plugin/Block/GroupHeroBlock.php
- 10.3.x modules/social_features/social_group/src/Plugin/Block/GroupHeroBlock.php
- 10.0.x modules/social_features/social_group/src/Plugin/Block/GroupHeroBlock.php
- 10.1.x modules/social_features/social_group/src/Plugin/Block/GroupHeroBlock.php
- 10.2.x modules/social_features/social_group/src/Plugin/Block/GroupHeroBlock.php
Namespace
Drupal\social_group\Plugin\BlockFile
modules/social_features/social_group/src/Plugin/Block/GroupHeroBlock.phpView source
<?php
namespace Drupal\social_group\Plugin\Block;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Session\AccountInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides a 'GroupHeroBlock' block.
*
* @Block(
* id = "group_hero_block",
* admin_label = @Translation("Group hero block"),
* context = {
* "group" = @ContextDefinition("entity:group", required = FALSE)
* }
* )
*/
class GroupHeroBlock extends BlockBase implements ContainerFactoryPluginInterface {
/**
* The route match.
*
* @var \Drupal\Core\Routing\RouteMatchInterface
*/
protected $routeMatch;
/**
* Creates a GroupHeroBlock instance.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The route match.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, RouteMatchInterface $route_match) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->routeMatch = $route_match;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('current_route_match'));
}
/**
* {@inheritdoc}
*/
public function build() {
$build = [];
$group = _social_group_get_current_group();
if (!empty($group)) {
// Content.
$content = \Drupal::entityTypeManager()
->getViewBuilder('group')
->view($group, 'hero');
$build['content'] = $content;
// Cache tags.
$build['#cache']['tags'][] = 'group_block:' . $group
->id();
}
// Cache contexts.
$build['#cache']['contexts'][] = 'url.path';
return $build;
}
/**
* {@inheritdoc}
*/
protected function blockAccess(AccountInterface $account) {
$current_route = $this->routeMatch
->getRouteName();
if ($current_route == 'entity.group_content.create_form') {
return AccessResult::forbidden();
}
return parent::blockAccess($account);
}
}
Classes
Name | Description |
---|---|
GroupHeroBlock | Provides a 'GroupHeroBlock' block. |