diff --git a/message_private.links.task.yml b/message_private.links.task.yml index 5240cc6..46b53c5 100644 --- a/message_private.links.task.yml +++ b/message_private.links.task.yml @@ -3,4 +3,7 @@ message_private.messages: route_name: message_private.messages base_route: entity.user.canonical title: 'Messages' +# Provide dynamic local tasks. +message_private.messages: + deriver: 'Drupal\message_private\Plugin\Derivative\MessagePrivateLocalTasks' weight: -10 \ No newline at end of file diff --git a/message_private.module b/message_private.module index c225342..5f337e0 100755 --- a/message_private.module +++ b/message_private.module @@ -275,7 +275,7 @@ function template_preprocess_message_private(&$variables) { // @see https://www.drupal.org/node/2195739 // $variables['name'] = theme('username', array('account' => user_load($uid))); - $variables['submitted'] = t('Submitted by !username on !datetime', array( + $variables['submitted'] = t('Sent by !username on !datetime', array( '!username' => $variables['name'], '!datetime' => $variables['date'], )); diff --git a/src/Form/MessagePrivateSettingsForm.php b/src/Form/MessagePrivateSettingsForm.php index 91c2d3b..bf876f4 100644 --- a/src/Form/MessagePrivateSettingsForm.php +++ b/src/Form/MessagePrivateSettingsForm.php @@ -91,8 +91,15 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#description' => t('Global On / Off checkbox for emails notifying users of a new private message'), ); + // Local action links on/off checkbox. + $form[MESSAGE_PRIVATE_LOCAL_ACTION] = array( + '#type' => 'checkbox', + '#title' => t('Disable Create a New Message local action links'), + '#default_value' => variable_get(MESSAGE_PRIVATE_LOCAL_ACTION, FALSE), + '#description' => t('Disable local action links to create new message on user pages.'), + ); - // Role based message create limit on/off checkbox. + // Role based message create limit on/off checkbox. $form[MESSAGE_PRIVATE_MESSAGE_LIMIT] = array( '#type' => 'checkbox', '#title' => t('Limit Message Create By Role'), diff --git a/src/Plugin/Derivative/MessagePrivateLocalTasks.php b/src/Plugin/Derivative/MessagePrivateLocalTasks.php new file mode 100644 index 0000000..a19135f --- /dev/null +++ b/src/Plugin/Derivative/MessagePrivateLocalTasks.php @@ -0,0 +1,31 @@ +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; + } +} + +?> \ No newline at end of file diff --git a/src/Plugin/views/access/MessagePrivateInbox.php b/src/Plugin/views/access/MessagePrivateInbox.php new file mode 100644 index 0000000..8984e63 --- /dev/null +++ b/src/Plugin/views/access/MessagePrivateInbox.php @@ -0,0 +1,158 @@ +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 []; + } + +}