Skip to content
Snippets Groups Projects

Draft: Issue #3295929 "Translate labels for StepsBlock block"

Open Theodoros Ploumis requested to merge issue/opigno_learning_path-3295929:3.x into 3.x
1 file
+ 40
13
Compare changes
  • Side-by-side
  • Inline
@@ -40,8 +40,8 @@ class StepsBlock extends BlockBase implements ContainerFactoryPluginInterface, T
*/
public function __construct(
array $configuration,
$plugin_id,
$plugin_definition,
$plugin_id,
$plugin_definition,
OpignoGroupContentTypesManager $opigno_group_content_types_manager
) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
@@ -54,8 +54,8 @@ class StepsBlock extends BlockBase implements ContainerFactoryPluginInterface, T
public static function create(
ContainerInterface $container,
array $configuration,
$plugin_id,
$plugin_definition) {
$plugin_id,
$plugin_definition) {
return new static(
$configuration,
$plugin_id,
@@ -81,8 +81,9 @@ class StepsBlock extends BlockBase implements ContainerFactoryPluginInterface, T
* {@inheritdoc}
*/
public function getGroupByRouteOrContext() {
// By default a getCurrentGroupId gets a group by orute parameter.
return Group::load($this->getCurrentGroupId());
// By default a getCurrentGroupId gets a group by route parameter.
$group_initial = Group::load($this->getCurrentGroupId());
return \Drupal::service('entity.repository')->getTranslationFromContext($group_initial);
}
/**
@@ -90,7 +91,6 @@ class StepsBlock extends BlockBase implements ContainerFactoryPluginInterface, T
*/
public function build() {
$group = $this->getGroupByRouteOrContext();
$steps = $group instanceof GroupInterface ? $this->getStepsByGroup($group) : [];
// Get group context.
@@ -134,7 +134,7 @@ class StepsBlock extends BlockBase implements ContainerFactoryPluginInterface, T
foreach ($elements["steps"] as &$step) {
$link = $this->getLinkToStart($step);
$step = [
// @todo seems it is a bad idea to generate a thme based on typology.
// @todo seems it is a bad idea to generate a the based on typology.
'#theme' => sprintf('%s_%s', 'opigno_lp_step', strtolower($step["typology"])),
'step' => $step,
'#state' => $this->getState($step),
@@ -213,8 +213,14 @@ class StepsBlock extends BlockBase implements ContainerFactoryPluginInterface, T
* Activity pre-processor.
*/
public function processActivityStatus($elements) {
/**
* @var $activity \Drupal\opigno_module\Entity\OpignoActivity
*/
$activity = $elements['#activity'];
$translation = \Drupal::service('entity.repository')->getTranslationFromContext($activity);
$elements['title'] = [
'#markup' => $elements['#activity']->label(),
'#markup' => $translation->label(),
];
return $elements;
}
@@ -243,6 +249,7 @@ class StepsBlock extends BlockBase implements ContainerFactoryPluginInterface, T
*/
protected function getLink($step): Url {
$content_step = OpignoGroupManagedContent::load($step['cid']);
/** @var \Drupal\opigno_group_manager\ContentTypeBase $content_type */
$content_type = $this->opignoGroupContentTypesManager->createInstance($content_step->getGroupContentTypeId());
$step_url = $content_type->getStartContentUrl($content_step->getEntityId(), $this->getCurrentGroupId());
@@ -297,16 +304,36 @@ class StepsBlock extends BlockBase implements ContainerFactoryPluginInterface, T
}
/** @var \Drupal\opigno_group_manager\OpignoGroupContent $content */
$content = $this->entityTypeManager()
$content_initial = $this->entityTypeManager()
->getStorage('opigno_group_content')
->load($step_training["cid"]);
$training = ($content instanceof OpignoGroupManagedContent) ? $content->getGroup() : NULL;
$course = ($step_training["id"] ? $this->entityTypeManager()
$content = \Drupal::service('entity.repository')->getTranslationFromContext($content_initial);
$training_initial = ($content instanceof OpignoGroupManagedContent) ? $content->getGroup() : NULL;
if ($training_initial) {
$training = \Drupal::service('entity.repository')->getTranslationFromContext($training_initial);
} else {
$training = NULL;
}
$course_initial = ($step_training["id"] ? $this->entityTypeManager()
->getStorage('group')
->load($step_training["id"]) : FALSE) ?: NULL;
$module = $this->entityTypeManager()
if ($course_initial) {
$course = \Drupal::service('entity.repository')->getTranslationFromContext($course_initial);
} else {
$course = NULL;
}
$module_initial = $this->entityTypeManager()
->getStorage('opigno_module')
->load($step["id"]) ?: NULL;
if ($module_initial) {
$module = \Drupal::service('entity.repository')->getTranslationFromContext($module_initial);
} else {
$module = NULL;
}
return [$training, $course, $module];
}
Loading