You are here

protected function GroupNodeController::addPageBundles in Group 8

Same name and namespace in other branches
  1. 2.0.x modules/gnode/src/Controller/GroupNodeController.php \Drupal\gnode\Controller\GroupNodeController::addPageBundles()

Retrieves a list of available bundles for the add page.

Parameters

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

bool $create_mode: Whether the target entity still needs to be created.

Return value

array An array of group content type IDs, keyed by the plugin that was used to generate their respective group content types.

Overrides GroupContentController::addPageBundles

See also

::addPage()

1 call to GroupNodeController::addPageBundles()
GroupNodeController::addPage in modules/gnode/src/Controller/GroupNodeController.php
Provides the group content creation overview page.

File

modules/gnode/src/Controller/GroupNodeController.php, line 92

Class

GroupNodeController
Returns responses for 'group_node' GroupContent routes.

Namespace

Drupal\gnode\Controller

Code

protected function addPageBundles(GroupInterface $group, $create_mode) {
  $bundles = [];

  // Retrieve all group_node plugins for the group's type.
  $plugin_ids = $this->pluginManager
    ->getInstalledIds($group
    ->getGroupType());
  foreach ($plugin_ids as $key => $plugin_id) {
    if (strpos($plugin_id, 'group_node:') !== 0) {
      unset($plugin_ids[$key]);
    }
  }

  // Retrieve all of the responsible group content types, keyed by plugin ID.
  $storage = $this->entityTypeManager
    ->getStorage('group_content_type');
  $properties = [
    'group_type' => $group
      ->bundle(),
    'content_plugin' => $plugin_ids,
  ];
  foreach ($storage
    ->loadByProperties($properties) as $bundle => $group_content_type) {

    /** @var \Drupal\group\Entity\GroupContentTypeInterface $group_content_type */
    $bundles[$group_content_type
      ->getContentPluginId()] = $bundle;
  }
  return $bundles;
}