function BlockContentDevelGenerate::develGenerateContentAddBlockTranslation
Create translation for the given block.
Parameters
array $results: Results array.
\Drupal\block_content\BlockContentInterface $block: Block to add translations to.
Throws
\Drupal\Core\Entity\EntityStorageException
1 call to BlockContentDevelGenerate::develGenerateContentAddBlockTranslation()
- BlockContentDevelGenerate::develGenerateContentAddBlock in devel_generate/
src/ Plugin/ DevelGenerate/ BlockContentDevelGenerate.php - Create one block. Used by both batch and non-batch code branches.
File
-
devel_generate/
src/ Plugin/ DevelGenerate/ BlockContentDevelGenerate.php, line 412
Class
- BlockContentDevelGenerate
- Provides a BlockContentDevelGenerate plugin.
Namespace
Drupal\devel_generate\Plugin\DevelGenerateCode
protected function develGenerateContentAddBlockTranslation(array &$results, BlockContentInterface $block) : void {
if (empty($results['translate_language'])) {
return;
}
if (is_null($this->contentTranslationManager)) {
return;
}
if (!$this->contentTranslationManager
->isEnabled('block_content', $block->bundle())) {
return;
}
if ($block->get('langcode')
->getLangcode() === LanguageInterface::LANGCODE_NOT_SPECIFIED || $block->get('langcode')
->getLangcode() === LanguageInterface::LANGCODE_NOT_APPLICABLE) {
return;
}
if (!isset($results['num_translations'])) {
$results['num_translations'] = 0;
}
// Translate the block to each target language.
$skip_languages = [
LanguageInterface::LANGCODE_NOT_SPECIFIED,
LanguageInterface::LANGCODE_NOT_APPLICABLE,
$block->get('langcode')
->getLangcode(),
];
foreach ($results['translate_language'] as $langcode) {
if (in_array($langcode, $skip_languages)) {
continue;
}
$translation_block = $block->addTranslation($langcode);
$translation_block->setInfo($block->label() . ' (' . $langcode . ')');
$this->populateFields($translation_block);
$translation_block->save();
++$results['num_translations'];
}
}