/** * Constructs a SolutionContentBlock. * * @param array $configuration * A configuration array containing information about the plugin instance. * @param string $plugin_id * The plugin_id for the plugin instance. * @param string $plugin_definition * The plugin implementation definition. * @param \Drupal\Core\Routing\RouteMatchInterface $current_route_match * The route matcher. * @param \Drupal\Core\Entity\EntityManager $entity_manager * The deprecated entity manager. * @param \Drupal\Core\Plugin\Context\ContextProviderInterface $solution_context * The context provider for the solution context. * * @todo EntityManager is deprecated. Use EntityTypeManager instead. * * @see https://webgate.ec.europa.eu/CITnet/jira/browse/ISAICP-2669 */ public function __construct(array $configuration, $plugin_id, $plugin_definition, RouteMatchInterface $current_route_match, EntityManager $entity_manager, ContextProviderInterface $solution_context) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->currentRouteMatch = $current_route_match; if (!empty($solution_context->getRuntimeContexts(['solution'])['solution'])) { $this->solution = $solution_context->getRuntimeContexts(['solution'])['solution']->getContextValue(); } $this->entityManager = $entity_manager; }
/** * Constructs a CollectionContentBlock object. * * @param array $configuration * A configuration array containing information about the plugin instance. * @param string $plugin_id * The plugin ID for the plugin instance. * @param string $plugin_definition * The plugin implementation definition. * @param \Drupal\Core\Routing\RouteMatchInterface $current_route_match * The current route match service. * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager * The entity type manager. * @param \Drupal\Core\Plugin\Context\ContextProviderInterface $collection_context * The collection context. * @param \Drupal\og\MembershipManagerInterface $membership_manager * The OG membership manager. */ public function __construct(array $configuration, $plugin_id, $plugin_definition, RouteMatchInterface $current_route_match, EntityTypeManagerInterface $entity_type_manager, ContextProviderInterface $collection_context, MembershipManagerInterface $membership_manager) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->currentRouteMatch = $current_route_match; $this->collection = $collection_context->getRuntimeContexts(['og'])['og']->getContextValue(); $this->entityTypeManager = $entity_type_manager; $this->membershipManager = $membership_manager; }
/** * {@inheritdoc} */ public function build() { $links = []; // Add a link to propose a collection. This is visible for everyone, even // anonymous users. $links['collection'] = ['#title' => $this->t('Propose collection'), '#url' => Url::fromRoute('rdf_entity.propose_form', ['rdf_type' => 'collection'])]; // Add a link to propose a solution. This is visible for everyone, even // anonymous users. $links['solution'] = ['#title' => $this->t('Propose solution'), '#url' => Url::fromRoute('rdf_entity.propose_form', ['rdf_type' => 'solution'])]; // Retrieve the collection from the context service. This needs to be done // manually since this is an optional context. Core only supports required // contexts (the ones that are enabled through the visibility conditions in // the block configuration). This also means we have to take care of the // caching ourselves. /** @var \Drupal\Core\Plugin\Context\Context[] $collection_contexts */ $collection_contexts = $this->collectionContext->getRuntimeContexts(['og']); if ($collection_contexts && $collection_contexts['og']->hasContextValue()) { $page_url = Url::fromRoute('custom_page.collection_custom_page.add', ['rdf_entity' => $collection_contexts['og']->getContextValue()->id()]); if ($page_url->access()) { $links['custom_page'] = ['#type' => 'link', '#title' => $this->t('Add custom page'), '#url' => $page_url, '#attributes' => ['class' => ['button', 'button--small']]]; } $solution_url = Url::fromRoute('solution.collection_solution.add', ['rdf_entity' => $collection_contexts['og']->getContextValue()->id()]); if ($solution_url->access()) { $links['solution'] = ['#type' => 'link', '#title' => $this->t('Add solution'), '#url' => $solution_url, '#attributes' => ['class' => ['button', 'button--small']]]; } // 'Add discussion' link. $discussion_url = Url::fromRoute('joinup_discussion.rdf_entity_discussion.add', ['rdf_entity' => $collection_contexts['og']->getContextValue()->id()]); if ($discussion_url->access()) { $links['discussion'] = ['#type' => 'link', '#title' => $this->t('Add discussion'), '#url' => $discussion_url, '#attributes' => ['class' => ['button', 'button--small']]]; } } /** @var \Drupal\Core\Plugin\Context\Context[] $solution_contexts */ $solution_contexts = $this->solutionContext->getRuntimeContexts(['solution']); if ($solution_contexts && $solution_contexts['solution']->hasContextValue()) { $release_url = Url::fromRoute('asset_release.solution_asset_release.add', ['rdf_entity' => $solution_contexts['solution']->getContextValue()->id()]); if ($release_url->access()) { $links['asset_release'] = ['#type' => 'link', '#title' => $this->t('Add release'), '#url' => $release_url, '#attributes' => ['class' => ['button', 'button--small']]]; } } if ($collection_contexts && $collection_contexts['og']->hasContextValue() || $solution_contexts && $solution_contexts['solution']->hasContextValue()) { $id = NULL; if ($collection_contexts['og']->hasContextValue()) { $id = $collection_contexts['og']->getContextValue()->id(); } if ($solution_contexts['solution']->hasContextValue()) { $id = $solution_contexts['solution']->getContextValue()->id(); } if ($id) { // 'Add news' link. $news_url = Url::fromRoute('joinup_news.rdf_entity_news.add', ['rdf_entity' => $id]); if ($news_url->access()) { $links['news'] = ['#type' => 'link', '#title' => $this->t('Add news'), '#url' => $news_url, '#attributes' => ['class' => ['button', 'button--small']]]; } // 'Add discussion' link. $discussion_url = Url::fromRoute('joinup_discussion.rdf_entity_discussion.add', ['rdf_entity' => $id]); if ($discussion_url->access()) { $links['discussion'] = ['#type' => 'link', '#title' => $this->t('Add discussion'), '#url' => $discussion_url, '#attributes' => ['class' => ['button', 'button--small']]]; } // 'Add document' link. $document_url = Url::fromRoute('joinup_document.rdf_entity_document.add', ['rdf_entity' => $id]); if ($document_url->access()) { $links['document'] = ['#type' => 'link', '#title' => $this->t('Add document'), '#url' => $document_url, '#attributes' => ['class' => ['button', 'button--small']]]; } // 'Add event' link. $event_url = Url::fromRoute('joinup_event.rdf_entity_event.add', ['rdf_entity' => $id]); if ($event_url->access()) { $links['event'] = ['#type' => 'link', '#title' => $this->t('Add event'), '#url' => $event_url, '#attributes' => ['class' => ['button', 'button--small']]]; } } } if (!empty($this->assetReleaseContext)) { /** @var \Drupal\Core\Plugin\Context\Context[] $asset_release_contexts */ $asset_release_contexts = $this->assetReleaseContext->getRuntimeContexts(['asset_release']); if ($asset_release_contexts && $asset_release_contexts['asset_release']->hasContextValue()) { $distribution_url = Url::fromRoute('asset_distribution.asset_release_asset_distribution.add', ['rdf_entity' => $asset_release_contexts['asset_release']->getContextValue()->id()]); if ($distribution_url->access()) { $links['asset_distribution'] = ['#type' => 'link', '#title' => $this->t('Add distribution'), '#url' => $distribution_url, '#attributes' => ['class' => ['button', 'button--small']]]; } } } $licence_url = Url::fromRoute('joinup_licence.add'); if ($licence_url->access()) { $links['licence'] = ['#title' => $this->t('Add licence'), '#url' => $licence_url]; } // Render the links as an unordered list, styled as buttons. $build = ['#theme' => 'item_list', '#list_type' => 'ul']; foreach ($links as $key => $link) { $link += ['#type' => 'link', '#attributes' => ['class' => ['button', 'button--small']]]; $build['#items'][$key] = $link; } return $build; }