forked from mccrodp/message_private
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added changes introduced by alpha-6 for D7: https://www.drupal.org/no…
- Loading branch information
mccrodp
committed
Apr 3, 2016
1 parent
1b386e7
commit 2f066f9
Showing
5 changed files
with
201 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
/** | ||
* @file | ||
* Contains \Drupal\message_private\Plugin\Derivative\MessagePrivateLocalTasks. | ||
*/ | ||
|
||
namespace Drupal\message_private\Plugin\Derivative; | ||
|
||
use Drupal\Component\Plugin\Derivative\DeriverBase; | ||
|
||
/** | ||
* Defines dynamic local tasks. | ||
*/ | ||
class DynamicLocalTasks extends DeriverBase { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getDerivativeDefinitions($base_plugin_definition) { | ||
// Create the "Create message for___" tasks. | ||
// @todo set no task for 'user/%' 'user/%/messages' where variable_get('message_private_local_action_links', FALSE) | ||
// @todo: to be set only for users with private message permissions. | ||
$this->derivatives['message_private.messages'] = $base_plugin_definition; | ||
$this->derivatives['message_private.messages']['title'] = 'Messages'; | ||
// @todo: this should pass a user / uid argument also. | ||
$this->derivatives['message_private.messages']['route_name'] = 'message_private.user.create_message'; | ||
return $this->derivatives; | ||
} | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Contains \Drupal\message_private\Plugin\views\access\MessagePrivateInbox. | ||
*/ | ||
|
||
namespace Drupal\message_private\Plugin\views\access; | ||
|
||
use Drupal\Core\Cache\Cache; | ||
use Drupal\Core\Cache\CacheableDependencyInterface; | ||
use Drupal\Core\Extension\ModuleHandlerInterface; | ||
use Drupal\Core\Form\FormStateInterface; | ||
use Drupal\Core\Session\AccountInterface; | ||
use Drupal\user\PermissionHandlerInterface; | ||
use Drupal\views\Plugin\views\access\AccessPluginBase; | ||
use Symfony\Component\DependencyInjection\ContainerInterface; | ||
use Symfony\Component\Routing\Route; | ||
|
||
/** | ||
* Access plugin that provides user and permission-based access control. | ||
* | ||
* @ingroup views_access_plugins | ||
* | ||
* @ViewsAccess( | ||
* id = "perm", | ||
* title = @Translation("Message Private Inbox"), | ||
* help = @Translation("Access will be granted for user's own inbox / users with bypass permissions.") | ||
* ) | ||
*/ | ||
// @todo: rework access plugin to that of D7: http://cgit.drupalcode.org/message_private/tree/message_private_access_plugin.inc | ||
class Permission extends AccessPluginBase implements CacheableDependencyInterface { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected $usesOptions = TRUE; | ||
|
||
/** | ||
* The permission handler. | ||
* | ||
* @var \Drupal\user\PermissionHandlerInterface | ||
*/ | ||
protected $permissionHandler; | ||
|
||
/** | ||
* The module handler. | ||
* | ||
* @var \Drupal\Core\Extension\ModuleHandlerInterface | ||
*/ | ||
protected $moduleHandler; | ||
|
||
/** | ||
* Constructs a Permission object. | ||
* | ||
* @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\user\PermissionHandlerInterface $permission_handler | ||
* The permission handler. | ||
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler | ||
* The module handler. | ||
*/ | ||
public function __construct(array $configuration, $plugin_id, $plugin_definition, PermissionHandlerInterface $permission_handler, ModuleHandlerInterface $module_handler) { | ||
parent::__construct($configuration, $plugin_id, $plugin_definition); | ||
$this->permissionHandler = $permission_handler; | ||
$this->moduleHandler = $module_handler; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { | ||
return new static( | ||
$configuration, | ||
$plugin_id, | ||
$plugin_definition, | ||
$container->get('user.permissions'), | ||
$container->get('module_handler') | ||
); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function access(AccountInterface $account) { | ||
return $account->hasPermission($this->options['perm']); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function alterRouteDefinition(Route $route) { | ||
$route->setRequirement('_permission', $this->options['perm']); | ||
} | ||
|
||
public function summaryTitle() { | ||
$permissions = $this->permissionHandler->getPermissions(); | ||
if (isset($permissions[$this->options['perm']])) { | ||
return $permissions[$this->options['perm']]['title']; | ||
} | ||
|
||
return $this->t($this->options['perm']); | ||
} | ||
|
||
|
||
protected function defineOptions() { | ||
$options = parent::defineOptions(); | ||
$options['perm'] = array('default' => 'access content'); | ||
|
||
return $options; | ||
} | ||
|
||
public function buildOptionsForm(&$form, FormStateInterface $form_state) { | ||
parent::buildOptionsForm($form, $form_state); | ||
// Get list of permissions | ||
$perms = []; | ||
$permissions = $this->permissionHandler->getPermissions(); | ||
foreach ($permissions as $perm => $perm_item) { | ||
$provider = $perm_item['provider']; | ||
$display_name = $this->moduleHandler->getName($provider); | ||
$perms[$display_name][$perm] = strip_tags($perm_item['title']); | ||
} | ||
|
||
$form['perm'] = array( | ||
'#type' => 'select', | ||
'#options' => $perms, | ||
'#title' => $this->t('Permission'), | ||
'#default_value' => $this->options['perm'], | ||
'#description' => $this->t('Only users with the selected permission flag will be able to access this display.'), | ||
); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getCacheMaxAge() { | ||
return Cache::PERMANENT; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getCacheContexts() { | ||
return ['user.permissions']; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getCacheTags() { | ||
return []; | ||
} | ||
|
||
} |