class ContentTranslationPermissions in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/content_translation/src/ContentTranslationPermissions.php \Drupal\content_translation\ContentTranslationPermissions
Provides dynamic permissions for the content_translation module.
Hierarchy
- class \Drupal\content_translation\ContentTranslationPermissions implements ContainerInjectionInterface uses StringTranslationTrait
Expanded class hierarchy of ContentTranslationPermissions
File
- core/
modules/ content_translation/ src/ ContentTranslationPermissions.php, line 18 - Contains \Drupal\content_translation\ContentTranslationPermissions.
Namespace
Drupal\content_translationView source
class ContentTranslationPermissions implements ContainerInjectionInterface {
use StringTranslationTrait;
/**
* The entity manager.
*
* @var \Drupal\Core\Entity\EntityManagerInterface
*/
protected $entityManager;
/**
* The content translation manager.
*
* @var \Drupal\content_translation\ContentTranslationManagerInterface
*/
protected $contentTranslationManager;
/**
* Constructs a ContentTranslationPermissions instance.
*
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
* @param \Drupal\content_translation\ContentTranslationManagerInterface $content_translation_manager
* The content translation manager.
*/
public function __construct(EntityManagerInterface $entity_manager, ContentTranslationManagerInterface $content_translation_manager) {
$this->entityManager = $entity_manager;
$this->contentTranslationManager = $content_translation_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('entity.manager'), $container
->get('content_translation.manager'));
}
/**
* Returns an array of content translation permissions.
*
* @return array
*/
public function contentPermissions() {
$permission = [];
// Create a translate permission for each enabled entity type and (optionally)
// bundle.
foreach ($this->entityManager
->getDefinitions() as $entity_type_id => $entity_type) {
if ($permission_granularity = $entity_type
->getPermissionGranularity()) {
$t_args = [
'@entity_label' => $entity_type
->getLowercaseLabel(),
];
switch ($permission_granularity) {
case 'bundle':
foreach ($this->entityManager
->getBundleInfo($entity_type_id) as $bundle => $bundle_info) {
if ($this->contentTranslationManager
->isEnabled($entity_type_id, $bundle)) {
$t_args['%bundle_label'] = isset($bundle_info['label']) ? $bundle_info['label'] : $bundle;
$permission["translate {$bundle} {$entity_type_id}"] = [
'title' => $this
->t('Translate %bundle_label @entity_label', $t_args),
];
}
}
break;
case 'entity_type':
if ($this->contentTranslationManager
->isEnabled($entity_type_id)) {
$permission["translate {$entity_type_id}"] = [
'title' => $this
->t('Translate @entity_label', $t_args),
];
}
break;
}
}
}
return $permission;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ContentTranslationPermissions:: |
protected | property | The content translation manager. | |
ContentTranslationPermissions:: |
protected | property | The entity manager. | |
ContentTranslationPermissions:: |
public | function | Returns an array of content translation permissions. | |
ContentTranslationPermissions:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
|
ContentTranslationPermissions:: |
public | function | Constructs a ContentTranslationPermissions instance. | |
StringTranslationTrait:: |
protected | property | The string translation service. | |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |