Skip to content
Permalink
Browse files

3275 remove translation code (#3822)

* Remove translation related code from the classes and etc.

* We keep langcode, because it is the default field
  • Loading branch information...
LOBsTerr authored and jmolivas committed Apr 22, 2018
1 parent 3e5a458 commit f5fd6de208cffd37588b785605cc2280738492c2
@@ -182,11 +182,13 @@ public function generate(array $parameters)
$moduleFormPath . 'RevisionDeleteForm.php',
$parameters
);
$this->renderFile(
'module/src/Entity/Form/entity-content-revision-revert-translation.php.twig',
$moduleFormPath . 'RevisionRevertTranslationForm.php',
$parameters
);
if ($is_translatable) {
$this->renderFile(
'module/src/Entity/Form/entity-content-revision-revert-translation.php.twig',
$moduleFormPath . 'RevisionRevertTranslationForm.php',
$parameters
);
}
$this->renderFile(
'module/src/Entity/Form/entity-content-revision-revert.php.twig',
$moduleFormPath . 'RevisionRevertForm.php',
@@ -65,15 +65,19 @@ class {{ entity_class }}Controller extends ControllerBase implements ContainerIn
*/
public function revisionOverview({{ entity_class }}Interface ${{ entity_name }}) {
$account = $this->currentUser();
${{ entity_name }}_storage = $this->entityManager()->getStorage('{{ entity_name }}');

{% if is_translatable %}
$langcode = ${{ entity_name }}->language()->getId();
$langname = ${{ entity_name }}->language()->getName();
$languages = ${{ entity_name }}->getTranslationLanguages();
$has_translations = (count($languages) > 1);
${{ entity_name }}_storage = $this->entityManager()->getStorage('{{ entity_name }}');

$build['#title'] = $has_translations ? $this->t('@langname revisions for %title', ['@langname' => $langname, '%title' => ${{ entity_name }}->label()]) : $this->t('Revisions for %title', ['%title' => ${{ entity_name }}->label()]);
$header = [$this->t('Revision'), $this->t('Operations')];
{% else %}
$build['#title'] = $this->t('Revisions for %title', ['%title' => ${{ entity_name }}->label()]);
{% endif %}

$header = [$this->t('Revision'), $this->t('Operations')];
$revert_permission = (($account->hasPermission("revert all {{ label|lower }} revisions") || $account->hasPermission('administer {{ label|lower }} entities')));
$delete_permission = (($account->hasPermission("delete all {{ label|lower }} revisions") || $account->hasPermission('administer {{ label|lower }} entities')));

@@ -86,9 +90,11 @@ class {{ entity_class }}Controller extends ControllerBase implements ContainerIn
foreach (array_reverse($vids) as $vid) {
/** @var \Drupal\{{ module }}\{{ entity_class }}Interface $revision */
$revision = ${{ entity_name }}_storage->loadRevision($vid);
{% if is_translatable %}
// Only show revisions that are affected by the language that is being
// displayed.
if ($revision->hasTranslation($langcode) && $revision->getTranslation($langcode)->isRevisionTranslationAffected()) {
{% endif %}
$username = [
'#theme' => 'username',
'#account' => $revision->getRevisionUser(),
@@ -161,7 +167,9 @@ class {{ entity_class }}Controller extends ControllerBase implements ContainerIn
}

$rows[] = $row;
{% if is_translatable %}
}
{% endif %}
}

$build['{{ entity_name }}_revisions_table'] = [
@@ -64,9 +64,7 @@ use Drupal\user\UserInterface;
* revision_table = "{{ entity_name }}_revision",
* revision_data_table = "{{ entity_name }}_field_revision",
{% endif %}
{% if is_translatable %}
* translatable = TRUE,
{% endif %}
* translatable = {{ is_translatable ? 'TRUE' : 'FALSE' }},
* admin_permission = "administer {{ label|lower }} entities",
* entity_keys = {
* "id" = "id",
@@ -152,6 +150,7 @@ class {{ entity_class }} extends {% if revisionable %}RevisionableContentEntityB
public function preSave(EntityStorageInterface $storage) {
parent::preSave($storage);

{% if is_translatable %}
foreach (array_keys($this->getTranslationLanguages()) as $langcode) {
$translation = $this->getTranslation($langcode);

@@ -160,6 +159,7 @@ class {{ entity_class }} extends {% if revisionable %}RevisionableContentEntityB
$translation->setOwnerId(0);
}
}
{% endif %}

// If no revision author has been set explicitly, make the {{ entity_name }} owner the
// revision author.
@@ -256,7 +256,9 @@ class {{ entity_class }} extends {% if revisionable %}RevisionableContentEntityB
->setRevisionable(TRUE)
->setSetting('target_type', 'user')
->setSetting('handler', 'default')
{% if is_translatable %}
->setTranslatable(TRUE)
{% endif %}
->setDisplayOptions('view', [
'label' => 'hidden',
'type' => 'author',
@@ -11,7 +11,9 @@ namespace Drupal\{{ module }};
{% block use_class %}
use Drupal\Core\Entity\Sql\SqlContentEntityStorage;
use Drupal\Core\Session\AccountInterface;
{% if is_translatable %}
use Drupal\Core\Language\LanguageInterface;
{% endif %}
use Drupal\{{ module }}\Entity\{{ entity_class }}Interface;
{% endblock %}

@@ -46,6 +48,7 @@ class {{ entity_class }}Storage extends SqlContentEntityStorage implements {{ en
[':uid' => $account->id()]
)->fetchCol();
}
{% if is_translatable %}

/**
* {@inheritdoc}
@@ -64,4 +67,5 @@ class {{ entity_class }}Storage extends SqlContentEntityStorage implements {{ en
->condition('langcode', $language->getId())
->execute();
}
{% endif %}
{% endblock %}
@@ -11,7 +11,9 @@ namespace Drupal\{{ module }};
{% block use_class %}
use Drupal\Core\Entity\ContentEntityStorageInterface;
use Drupal\Core\Session\AccountInterface;
{% if is_translatable %}
use Drupal\Core\Language\LanguageInterface;
{% endif %}
use Drupal\{{ module }}\Entity\{{ entity_class }}Interface;
{% endblock %}

@@ -48,7 +50,7 @@ interface {{ entity_class }}StorageInterface extends ContentEntityStorageInterfa
* {{ label }} revision IDs (in ascending order).
*/
public function userRevisionIds(AccountInterface $account);

{% if is_translatable %}
/**
* Counts the number of revisions in the default language.
*
@@ -67,4 +69,5 @@ interface {{ entity_class }}StorageInterface extends ContentEntityStorageInterfa
* The language object.
*/
public function clearRevisionsLanguage(LanguageInterface $language);
{% endif %}
{% endblock %}

0 comments on commit f5fd6de

Please sign in to comment.
You can’t perform that action at this time.