/** * Returns the distributions that are part of a solution. * * @param \Drupal\rdf_entity\RdfInterface $solution * The solution rdf entity. * * @return \Drupal\rdf_entity\RdfInterface[] * An array of distributions related to the solution. */ public function getSolutionDistributions(RdfInterface $solution) { $group_content_ids = $this->membershipManager->getGroupContentIds($solution, ['rdf_entity']); if (empty($group_content_ids['rdf_entity'])) { return []; } /** @var array $group_content */ $group_content = $this->entityTypeManager->getStorage('rdf_entity')->loadMultiple($group_content_ids['rdf_entity']); /** @var RdfInterface[] $distributions */ $distributions = array_filter($group_content, function (RdfInterface $entity) { return $entity->bundle() === 'asset_distribution'; }); return $distributions; }
/** * {@inheritdoc} */ public function getRuntimeContexts(array $unqualified_context_ids) { $result = []; $value = NULL; if (($route_object = $this->routeMatch->getRouteObject()) && ($route_contexts = $route_object->getOption('parameters')) && isset($route_contexts['rdf_entity'])) { /** @var \Drupal\rdf_entity\RdfInterface $collection */ if ($collection = $this->routeMatch->getParameter('rdf_entity')) { if ($collection->bundle() == 'collection') { $value = $collection; } } } elseif (($route_parameters = $this->routeMatch->getParameters()) && in_array($this->routeMatch->getRouteName(), $this->getSupportedRoutes())) { foreach ($route_parameters as $route_parameter) { if ($route_parameter instanceof ContentEntityInterface) { $bundle = $route_parameter->bundle(); $entity_type = $route_parameter->getEntityTypeId(); // Check if the object is a og content entity. if (Og::isGroupContent($entity_type, $bundle) && ($groups = $this->membershipManager->getGroupIds($route_parameter, 'rdf_entity', 'collection'))) { // A content can belong to only one rdf_entity. // Check that the content is not an orphaned one. if ($collection_id = reset($groups['rdf_entity'])) { $collection = Rdf::load($collection_id); $value = $collection; } } } } } $cacheability = new CacheableMetadata(); $cacheability->setCacheContexts(['route']); $collection_context_definition = new ContextDefinition('entity', $this->t('Organic group provided by collection'), FALSE); $context = new Context($collection_context_definition, $value); $context->addCacheableDependency($cacheability); $result['og'] = $context; return $result; }
/** * {@inheritdoc} */ public function build() { if (empty($this->collection)) { throw new \Exception('The "Collection content" block can only be shown on collection pages.'); } $content_ids = $this->membershipManager->getGroupContentIds($this->collection); $list = array(); foreach ($content_ids as $entity_type => $ids) { $storage = $this->entityTypeManager->getStorage($entity_type); $entities = $storage->loadMultiple($ids); $children = []; foreach ($entities as $entity) { $children[] = array('#markup' => $entity->link()); } if ($children) { $list[] = array('#markup' => $storage->getEntityType()->getLabel(), 'children' => $children); } } $build = array('list' => ['#theme' => 'item_list', '#items' => $list, '#cache' => ['tags' => ['og_group_content:' . $this->collection->id()]]]); return $build; }