You are here

public function OpignoModuleGroupController::addPage in Opigno module 3.x

Same name and namespace in other branches
  1. 8 modules/opigno_module_group/src/Controller/OpignoModuleGroupController.php \Drupal\opigno_module_group\Controller\OpignoModuleGroupController::addPage()

Provides the group content creation overview page.

Parameters

\Drupal\group\Entity\GroupInterface $group: The group to add the group content to.

bool $create_mode: (optional) Whether the target entity still needs to be created. Defaults to FALSE, meaning the target entity is assumed to exist already.

Return value

array|\Symfony\Component\HttpFoundation\RedirectResponse The group content creation overview page or a redirect to the form for adding group content if there is only one group content type.

Overrides GroupNodeController::addPage

File

modules/opigno_module_group/src/Controller/OpignoModuleGroupController.php, line 61

Class

OpignoModuleGroupController
Returns responses for 'group_node' GroupContent routes.

Namespace

Drupal\opigno_module_group\Controller

Code

public function addPage(GroupInterface $group, $create_mode = FALSE) {
  $build = parent::addPage($group, $create_mode);

  // Do not interfere with redirects.
  if (!is_array($build)) {
    return $build;
  }

  // Overwrite the label and description for all of the displayed bundles.
  $storage_handler = $this->entityTypeManager
    ->getStorage('node_type');
  foreach ($this
    ->addPageBundles($group, $create_mode) as $plugin_id => $bundle_name) {
    if (!empty($build['#bundles'][$bundle_name])) {
      $plugin = $group
        ->getGroupType()
        ->getContentPlugin($plugin_id);
      $bundle_label = $storage_handler
        ->load($plugin
        ->getEntityBundle())
        ->label();
      $t_args = [
        '%node_type' => $bundle_label,
      ];
      $description = $create_mode ? $this
        ->t('Create a node of type %node_type in the group.', $t_args) : $this
        ->t('Add an existing node of type %node_type to the group.', $t_args);
      $build['#bundles'][$bundle_name]['label'] = $bundle_label;
      $build['#bundles'][$bundle_name]['description'] = $description;
    }
  }
  return $build;
}