og-8.x-1.x-dev/src/Plugin/OgGroupResolver/RouteGroupResolver.php

src/Plugin/OgGroupResolver/RouteGroupResolver.php
<?php

declare(strict_types=1);

namespace Drupal\og\Plugin\OgGroupResolver;

use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\og\Attribute\OgGroupResolver;
use Drupal\og\OgResolvedGroupCollectionInterface;
use Drupal\og\OgRouteGroupResolverBase;

/**
 * Resolves the group from the route.
 *
 * This plugin inspects the current route and checks if it is an entity path for
 * a group entity.
 */
#[OgGroupResolver(
  id: 'route_group',
  label: new TranslatableMarkup('Group entity from current route'),
  description: new TranslatableMarkup('Checks if the current route is an entity path that belongs to a group entity.')
)]
class RouteGroupResolver extends OgRouteGroupResolverBase {

  /**
   * {@inheritdoc}
   */
  public function resolve(OgResolvedGroupCollectionInterface $collection) {
    $entity = $this->getContentEntity();
    if ($entity && $this->groupTypeManager->isGroup($entity->getEntityTypeId(), $entity->bundle())) {
      $collection->addGroup($entity, ['route']);

      // We are on a route that matches an entity path for a group entity. We
      // can conclude with 100% certainty that this group is relevant for the
      // current context. There's no need to keep searching.
      $this->stopPropagation();
    }
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc