ChangeMultipleOgMembershipRolesBase.php in Organic groups 8
File
src/Plugin/Action/ChangeMultipleOgMembershipRolesBase.php
View source
<?php
declare (strict_types=1);
namespace Drupal\og\Plugin\Action;
use Drupal\Core\Action\ActionBase;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\TempStore\PrivateTempStoreFactory;
use Drupal\og\OgAccessInterface;
use Drupal\og\OgMembershipInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
abstract class ChangeMultipleOgMembershipRolesBase extends ActionBase implements ContainerFactoryPluginInterface {
protected $ogAccess;
protected $tempStore;
public function __construct(array $configuration, $plugin_id, $plugin_definition, OgAccessInterface $og_access, PrivateTempStoreFactory $temp_store_factory) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->ogAccess = $og_access;
$this->tempStore = $temp_store_factory
->get($plugin_id);
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('og.access'), $container
->get('tempstore.private'));
}
public function executeMultiple(array $memberships) {
$membership_ids = array_map(function (OgMembershipInterface $membership) {
return $membership
->id();
}, $memberships);
$this->tempStore
->set('membership_ids', $membership_ids);
}
public function execute($object = NULL) {
$this
->executeMultiple([
$object,
]);
}
public function access($object, ?AccountInterface $account = NULL, $return_as_object = FALSE) {
$access = $this->ogAccess
->userAccess($object
->getGroup(), 'manage members', $account);
return $return_as_object ? $access : $access
->isAllowed();
}
}