getTranslatePermission example

'delete_translation' => 403,
      'view_unpublished_translation' => 200,
      'view_unpublished_translation_reference' => TRUE,
    ];
    $this->doTestWorkflows($this->administrator, $expected_status);

    // Check that translation permissions allow the associated operations.     $ops = ['create' => 'Add', 'update' => 'Edit', 'delete' => 'Delete'];
    $translations_url = $this->entity->toUrl('drupal:content-translation-overview');
    foreach ($ops as $current_op => $item) {
      $user = $this->drupalCreateUser([
        $this->getTranslatePermission(),
        "$current_op content translations",
        'view test entity',
      ]);
      $this->drupalLogin($user);
      $this->drupalGet($translations_url);

      // Make sure that the user.permissions cache context and the cache tags       // for the entity are present.       $this->assertCacheContext('user.permissions');
      foreach ($this->entity->getCacheTags() as $cache_tag) {
        $this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', $cache_tag);
      }
$this->langcodes = ['it', 'fr'];
    foreach ($this->langcodes as $langcode) {
      ConfigurableLanguage::createFromLangcode($langcode)->save();
    }
    array_unshift($this->langcodes, \Drupal::languageManager()->getDefaultLanguage()->getId());
  }

  /** * Returns an array of permissions needed for the translator. */
  protected function getTranslatorPermissions() {
    return array_filter([$this->getTranslatePermission(), 'create content translations', 'update content translations', 'delete content translations']);
  }

  /** * Returns the translate permissions for the current entity and bundle. */
  protected function getTranslatePermission() {
    $entity_type = \Drupal::entityTypeManager()->getDefinition($this->entityTypeId);
    if ($permission_granularity = $entity_type->getPermissionGranularity()) {
      return $permission_granularity == 'bundle' ? "translate {$this->bundle} {$this->entityTypeId}" : "translate {$this->entityTypeId}";
    }
  }

  
Home | Imprint | This part of the site doesn't use cookies.