public function BlockContentInlineBlockTranslateForm::getEntityFromRouteMatch in Layout Builder Symmetric Translations 8
Determines which entity will be used by this form from a RouteMatch object.
Parameters
\Drupal\Core\Routing\RouteMatchInterface $route_match: The route match.
string $entity_type_id: The entity type identifier.
Return value
\Drupal\Core\Entity\EntityInterface The entity object as determined from the passed-in route match.
Overrides EntityForm::getEntityFromRouteMatch
File
- src/
Form/ BlockContentInlineBlockTranslateForm.php, line 78
Class
- BlockContentInlineBlockTranslateForm
- Provides a form class for translating inline blocks in the Layout Builder.
Namespace
Drupal\layout_builder_st\FormCode
public function getEntityFromRouteMatch(RouteMatchInterface $route_match, $entity_type_id) {
/** @var \Drupal\layout_builder\TranslatableSectionStorageInterface $section_storage */
$translated_configuration = $this->sectionStorage
->getTranslatedComponentConfiguration($this->uuid);
$langcode = $this->sectionStorage
->getTranslationLanguage()
->getId();
if (!empty($translated_configuration)) {
if (!empty($translated_configuration['block_serialized'])) {
return unserialize($translated_configuration['block_serialized']);
}
elseif (!empty($translated_configuration['block_revision_id'])) {
/** @var \Drupal\block_content\BlockContentInterface $entity */
$entity = $this->entityTypeManager
->getStorage('block_content')
->loadRevision($translated_configuration['block_revision_id']);
$entity = $this->entityRepository
->getActive('block_content', $entity
->id());
if ($entity
->hasTranslation($langcode)) {
return $entity
->getTranslation($langcode);
}
}
}
$configuration = $this->sectionStorage
->getSection($this->delta)
->getComponent($this->uuid)
->getPlugin()
->getConfiguration();
if (!empty($configuration['block_revision_id'])) {
/** @var \Drupal\block_content\BlockContentInterface $entity */
$entity = $this->entityTypeManager
->getStorage('block_content')
->loadRevision($configuration['block_revision_id']);
$entity = $this->entityRepository
->getActive('block_content', $entity
->id());
if ($entity
->hasTranslation($langcode)) {
return $entity
->getTranslation($langcode);
}
else {
$translation = $entity
->addTranslation($langcode, $entity
->toArray());
if (!empty($translated_configuration['label'])) {
$translation
->setInfo($translated_configuration['label']);
}
return $translation;
}
}
else {
throw new \LogicException("InlineBlockTranslationForm should never be invoked without an available block_content entity");
}
}