You are here

protected function GroupMediaController::addPageBundles in Group Media 8.2

Same name and namespace in other branches
  1. 8 src/Controller/GroupMediaController.php \Drupal\groupmedia\Controller\GroupMediaController::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 GroupMediaController::addPageBundles()
GroupMediaController::addPage in src/Controller/GroupMediaController.php
Provides the group content creation overview page.

File

src/Controller/GroupMediaController.php, line 71

Class

GroupMediaController
Returns responses for 'group_media' GroupContent routes.

Namespace

Drupal\groupmedia\Controller

Code

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

  // Retrieve all group_media 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_media:') !== 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;
}