function WorkspaceProviderBase::entityTranslationInsert
Acts after an entity translation has been added.
Parameters
\Drupal\Core\Entity\EntityInterface $translation: The entity translation that was inserted.
Overrides WorkspaceProviderInterface::entityTranslationInsert
File
-
core/
modules/ workspaces/ src/ Provider/ WorkspaceProviderBase.php, line 214
Class
- WorkspaceProviderBase
- Defines the base class for workspace providers.
Namespace
Drupal\workspaces\ProviderCode
public function entityTranslationInsert(EntityInterface $translation) : void {
// When a new translation is added to an existing entity, we need to add
// that translation to the default revision as well, otherwise the new
// translation wouldn't show up in entity queries or views which use the
// field data table as the base table.
$default_revision = $this->workspaceManager
->executeOutsideWorkspace(function () use ($translation) {
return $this->entityTypeManager
->getStorage($translation->getEntityTypeId())
->load($translation->id());
});
$langcode = $translation->language()
->getId();
if (!$default_revision->hasTranslation($langcode)) {
$default_revision_translation = $default_revision->addTranslation($langcode, $translation->toArray());
assert($default_revision_translation instanceof EntityPublishedInterface);
$default_revision_translation->setUnpublished();
$default_revision_translation->setSyncing(TRUE);
$default_revision_translation->save();
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.