Skip to content

Commit

Permalink
3275 remove translation code (#3822)
Browse files Browse the repository at this point in the history
* 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 f5fd6de
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 12 deletions.
12 changes: 7 additions & 5 deletions src/Generator/EntityContentGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
14 changes: 11 additions & 3 deletions templates/module/src/Controller/entity-controller.php.twig
Original file line number Diff line number Diff line change
Expand Up @@ -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')));

Expand All @@ -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(),
Expand Down Expand Up @@ -161,7 +167,9 @@ class {{ entity_class }}Controller extends ControllerBase implements ContainerIn
}

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

$build['{{ entity_name }}_revisions_table'] = [
Expand Down
8 changes: 5 additions & 3 deletions templates/module/src/Entity/entity-content.php.twig
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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);

Expand All @@ -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.
Expand Down Expand Up @@ -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',
Expand Down
4 changes: 4 additions & 0 deletions templates/module/src/entity-storage.php.twig
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}

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

/**
* {@inheritdoc}
Expand All @@ -64,4 +67,5 @@ class {{ entity_class }}Storage extends SqlContentEntityStorage implements {{ en
->condition('langcode', $language->getId())
->execute();
}
{% endif %}
{% endblock %}
5 changes: 4 additions & 1 deletion templates/module/src/interface-entity-storage.php.twig
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}

Expand Down Expand Up @@ -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.
*
Expand All @@ -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.