CommentFlagType.php in Flag 8.4
File
src/Plugin/Flag/CommentFlagType.php
View source
<?php
namespace Drupal\flag\Plugin\Flag;
use Drupal\flag\FlagInterface;
class CommentFlagType extends EntityFlagType {
protected function getExtraPermissionsOptions() {
$options = parent::getExtraPermissionsOptions();
$options['parent_owner'] = $this
->t("Permissions based on ownership of a comment's parent entity.");
return $options;
}
public function actionPermissions(FlagInterface $flag) {
$permissions = parent::actionPermissions($flag);
if (!empty($this->configuration['extra_permissions'])) {
foreach ($this->configuration['extra_permissions'] as $option) {
switch ($option) {
case 'parent_owner':
$permissions['flag ' . $flag
->id() . ' comments on own parent entities'] = [
'title' => $this
->t('Flag %flag_title comments on own parent entities', [
'%flag_title' => $flag
->label(),
]),
];
$permissions['unflag ' . $flag
->id() . ' comments on own parent entities'] = [
'title' => $this
->t('Unflag %flag_title on own parent entities', [
'%flag_title' => $flag
->label(),
]),
];
$permissions['flag ' . $flag
->id() . ' comments on other parent entities'] = [
'title' => $this
->t("Flag %flag_title on others' parent entities", [
'%flag_title' => $flag
->label(),
]),
];
$permissions['unflag ' . $flag
->id() . ' comments on other parent entities'] = [
'title' => $this
->t("Unflag %flag_title on others' parent entities", [
'%flag_title' => $flag
->label(),
]),
];
break;
}
}
}
return $permissions;
}
}