local_translation-8.x-1.x-dev/modules/local_translation_content/src/Plugin/LocalTranslationAccessRules/ContentTranslationCreator1Rule.php
modules/local_translation_content/src/Plugin/LocalTranslationAccessRules/ContentTranslationCreator1Rule.php
<?php
namespace Drupal\local_translation_content\Plugin\LocalTranslationAccessRules;
use Drupal\Core\Entity\ContentEntityInterface;
/**
* Class ContentTranslationCreator1Rule.
*
* @package Drupal\local_translation_content\Plugin\LocalTranslationAccessRules
*
* @LocalTranslationAccessRule("local_translation_content_ct_creator_1")
*/
class ContentTranslationCreator1Rule extends AccessRuleBase {
/**
* {@inheritdoc}
*/
protected $limited = FALSE;
/**
* {@inheritdoc}
*/
protected $permissions = ['create content translations'];
/**
* {@inheritdoc}
*/
protected function addDynamicPermissions(ContentEntityInterface $entity) {
$bundle = $entity->bundle();
$entity_type_id = $entity->getEntityTypeId();
$this->permissions[] = "translate $bundle $entity_type_id";
}
/**
* {@inheritdoc}
*/
public function isAllowed($operation, ContentEntityInterface $entity, $langcode = NULL) {
if ($operation !== 'create') {
return FALSE;
}
return parent::isAllowed($operation, $entity, $langcode);
}
}
