Commit 256a21a2 authored by Kristiaan Van den Eynde's avatar Kristiaan Van den Eynde
Browse files

Issue #3280127 by kristiaanvandeneynde: Introduce a ui_text_provider handler

parent 31d6a9c8
Loading
Loading
Loading
Loading
+14 −0
Changes for group.install: 14 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -224,3 +224,17 @@ function group_update_9206() {
    $group_role->save(TRUE);
  }
}

/**
 * Remove label and description from group content types.
 */
function group_update_9207() {
  $config_factory = \Drupal::configFactory();

  foreach ($config_factory->listAll('group.content_type.') as $config_name) {
    $group_content_type = $config_factory->getEditable($config_name);
    $group_content_type->clear('label');
    $group_content_type->clear('description');
    $group_content_type->save(TRUE);
  }
}
+4 −0
Changes for group.services.yml: 4 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -157,6 +157,10 @@ services:
  group.relation_handler.post_install:
    class: 'Drupal\group\Plugin\Group\RelationHandlerDefault\PostInstall'
    shared: false
  group.relation_handler.ui_text_provider:
    class: 'Drupal\group\Plugin\Group\RelationHandlerDefault\UiTextProvider'
    arguments: ['@entity_type.manager', '@string_translation']
    shared: false

  # Specific group relation handlers.
  group.relation_handler.entity_reference.group_membership:

modules/gnode/gnode.routing.yml

deleted100644 → 0
+0 −2
Changes for modules/gnode/gnode.routing.yml: 0 added lines, 2 removed lines.
Original line number Diff line number Diff line
route_callbacks:
  - '\Drupal\gnode\Routing\GroupNodeRouteProvider::getRoutes'
+5 −0
Changes for modules/gnode/gnode.services.yml: 5 added lines, 0 removed lines.
Original line number Diff line number Diff line
services:
  gnode.route_subscriber:
    class: 'Drupal\gnode\Routing\RouteSubscriber'
    tags:
      - { name: 'event_subscriber' }

  # Group relation plugin handlers.
  group.relation_handler.operation_provider.group_node:
    class: 'Drupal\gnode\Plugin\Group\RelationHandler\GroupNodeOperationProvider'
+0 −115
Changes for modules/gnode/src/Controller/GroupNodeController.php: 0 added lines, 115 removed lines.
Original line number Diff line number Diff line
<?php

namespace Drupal\gnode\Controller;

use Drupal\Core\Entity\EntityFormBuilderInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Render\RendererInterface;
use Drupal\group\Entity\Controller\GroupContentController;
use Drupal\group\Entity\GroupContentTypeInterface;
use Drupal\group\Entity\GroupInterface;
use Drupal\group\Plugin\Group\Relation\GroupRelationTypeManagerInterface;
use Drupal\Core\TempStore\PrivateTempStoreFactory;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Returns responses for 'group_node' GroupContent routes.
 */
class GroupNodeController extends GroupContentController {

  /**
   * The group relation type manager.
   *
   * @var \Drupal\group\Plugin\Group\Relation\GroupRelationTypeManagerInterface
   */
  protected $pluginManager;

  /**
   * Constructs a new GroupNodeController.
   *
   * @param \Drupal\group\Plugin\Group\Relation\GroupRelationTypeManagerInterface $plugin_manager
   *   The group relation type manager.
   * @param \Drupal\Core\TempStore\PrivateTempStoreFactory $temp_store_factory
   *   The private store factory.
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager.
   * @param \Drupal\Core\Entity\EntityFormBuilderInterface $entity_form_builder
   *   The entity form builder.
   * @param \Drupal\Core\Render\RendererInterface $renderer
   *   The renderer.
   */
  public function __construct(GroupRelationTypeManagerInterface $plugin_manager, PrivateTempStoreFactory $temp_store_factory, EntityTypeManagerInterface $entity_type_manager, EntityFormBuilderInterface $entity_form_builder, RendererInterface $renderer) {
    parent::__construct($temp_store_factory, $entity_type_manager, $entity_form_builder, $renderer);
    $this->pluginManager = $plugin_manager;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static(
      $container->get('group_relation_type.manager'),
      $container->get('tempstore.private'),
      $container->get('entity_type.manager'),
      $container->get('entity.form_builder'),
      $container->get('renderer')
    );
  }

  /**
   * {@inheritdoc}
   */
  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])) {
        $group_relation_type = $group->getGroupType()->getPlugin($plugin_id)->getRelationType();
        $bundle_label = $storage_handler->load($group_relation_type->getEntityBundle())->label();

        $t_args = ['%node_type' => $bundle_label];
        $description = $create_mode
          ? $this->t('Add new content of type %node_type to the group.', $t_args)
          : $this->t('Add existing content of type %node_type to the group.', $t_args);

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

    return $build;
  }

  /**
   * {@inheritdoc}
   */
  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) {
      assert($group_content_type instanceof GroupContentTypeInterface);
      $bundles[$group_content_type->getPluginId()] = $bundle;
    }

    return $bundles;
  }

}
Loading