Commit 3fff8206 authored by Nikolay Lobachev's avatar Nikolay Lobachev
Browse files

Issue #3325129: Refactor code.

parent 194f7bfa
Loading
Loading
Loading
Loading
+8 −10
Original line number Diff line number Diff line
@@ -41,20 +41,18 @@ class GroupMediaController extends GroupRelationshipController {
    // Overwrite the label and description for all displayed bundles.
    $media_type_storage = $this->entityTypeManager->getStorage('media_type');
    $group_type = $group->getGroupType();
    foreach ($this->addPageBundles($group, $create_mode, $base_plugin_id) as $plugin_id => $bundle) {
      $bundle_name = $bundle->getOriginalId();
      if (!empty($build['#bundles'][$bundle_name])) {
        $plugin_id = $bundle->get('content_plugin');
        $plugin = $group_type->getPlugin($plugin_id);
        $bundle_type = $plugin->getRelationType()->getEntityBundle();
        $bundle_label = $media_type_storage->load($bundle_type)->label();
        $t_args = ['%media_type' => $bundle_label];
    foreach ($this->addPageBundles($group, $create_mode, $base_plugin_id) as $bundle_id => $bundle) {
      if (!empty($build['#bundles'][$bundle_id])) {
        $plugin = $group_type->getPlugin($bundle->getPluginId());
        $media_type = $plugin->getRelationType()->getEntityBundle();
        $media_type_label = $media_type_storage->load($media_type)->label();
        $t_args = ['%media_type' => $media_type_label];
        $description = $create_mode
          ? $this->t('Create a media of type %media_type in the group.', $t_args)
          : $this->t('Add an existing media of type %media_type to the group.', $t_args);

        $build['#bundles'][$bundle_name]['label'] = $bundle_label;
        $build['#bundles'][$bundle_name]['description'] = $description;
        $build['#bundles'][$bundle_id]['label'] = $media_type_label;
        $build['#bundles'][$bundle_id]['description'] = $description;
      }
    }