/** * Returns the solution that a release belongs to. * * @param \Drupal\rdf_entity\RdfInterface $asset_release * The asset release rdf entity. * * @return \Drupal\rdf_entity\RdfInterface * The solution rdf entity that the release is version of. */ public function getReleaseSolution(RdfInterface $asset_release) { if ($asset_release->bundle() != 'asset_release') { return NULL; } $target_id = $asset_release->field_isr_is_version_of->first()->target_id; return $this->entityTypeManager->getStorage('rdf_entity')->load($target_id); }
/** * Retrieve the initial state value of the entity. * * @param \Drupal\rdf_entity\RdfInterface $entity * The solution entity. * * @return string * The machine name value of the state. * * @see https://www.drupal.org/node/2745673 */ protected function getState(RdfInterface $entity) { if ($entity->isNew()) { return $entity->field_is_state->first()->value; } else { $unchanged_entity = \Drupal::entityTypeManager()->getStorage('rdf_entity')->loadUnchanged($entity->id()); return $unchanged_entity->field_is_state->first()->value; } }
/** * {@inheritdoc} */ public function access(Route $route, AccountInterface $account, RdfInterface $rdf_entity, $operation = 'view') { $graph = $route->getOption('graph_name'); $entity_type_id = $route->getOption('entity_type_id'); $storage = $this->entityManager->getStorage($entity_type_id); if (!$storage instanceof RdfEntitySparqlStorage) { throw new \Exception('Storage not supported.'); } // The active graph is the published graph. It is handled by the default // operation handler. // @todo: getActiveGraph is not the default. We should load from settings. $default_graph = $storage->getBundleGraphUri($rdf_entity->bundle(), 'default'); $requested_graph = $storage->getBundleGraphUri($rdf_entity->bundle(), $graph); if ($requested_graph == $default_graph) { return AccessResult::neutral(); } $active_graph_type = $storage->getRequestGraphs($rdf_entity->id()); // Check if there is an entity saved in the passed graph. $storage->setRequestGraphs($rdf_entity->id(), [$graph]); $entity = $storage->load($rdf_entity->id()); // Restore active graph. $storage->setRequestGraphs($rdf_entity->id(), $active_graph_type); // @todo: When the requested graph is the only one and it is not the // default, it is loaded in the default view, so maybe there is no need // to also show a separate tab. return AccessResult::allowedIf($entity && $this->checkAccess($rdf_entity, $route, $account, $operation, $graph))->cachePerPermissions()->addCacheableDependency($rdf_entity); }
/** * {@inheritdoc} */ public function build() { // If the page is not a solution page, return an empty form so that the // rendering of this block can be omitted. if (empty($this->solution) || $this->solution->bundle() != 'solution') { return []; } // Get news referencing to this solution. // @todo EntityManager is deprecated. Use EntityTypeManager instead. // @see https://webgate.ec.europa.eu/CITnet/jira/browse/ISAICP-2669 $entities = $this->entityManager->getStorage('node')->loadByProperties([OgGroupAudienceHelperInterface::DEFAULT_FIELD => $this->solution->id()]); $items = []; foreach ($entities as $entity) { $items[] = ['#markup' => $entity->link()]; } // Also retrieve related collections. $ids = $this->entityManager->getStorage('rdf_entity')->getQuery()->condition('field_ar_affiliates', $this->solution->id())->execute(); $entities = Rdf::loadMultiple($ids); foreach ($entities as $entity) { $items[] = ['#markup' => $entity->link()]; } // Build the array output. if ($items) { return ['list' => ['#theme' => 'item_list', '#items' => $items, '#cache' => ['tags' => ['entity:node:news', 'entity:rdf_entity:collection']]]]; } return []; }
/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { $user = User::load($this->currentUser()->id()); $membership = Og::getMembership($this->collection, $user); $membership->delete(); drupal_set_message($this->t('You are no longer a member of %collection.', ['%collection' => $this->collection->getName()])); // @todo: This is a temporary workaround for the lack of og cache // contexts/tags. Remove this when Og provides proper cache context. // @see: https://webgate.ec.europa.eu/CITnet/jira/browse/ISAICP-2628 Cache::invalidateTags(['user.roles']); $form_state->setRedirectUrl($this->getCancelUrl()); }
/** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state, AccountProxyInterface $user = NULL, RdfInterface $collection = NULL) { $form['#access'] = $this->access(); $user = User::load($user->id()); $form['collection_id'] = ['#type' => 'hidden', '#title' => $this->t('Collection ID'), '#value' => $collection->id()]; $form['user_id'] = ['#type' => 'hidden', '#title' => $this->t('User ID'), '#value' => $user->id()]; // If the user is already a member of the collection, show a link to the // confirmation form, disguised as a form submit button. The confirmation // form should open in a modal dialog for JavaScript-enabled browsers. if (Og::isMember($collection, $user)) { $form['leave'] = ['#type' => 'link', '#title' => $this->t('Leave this collection'), '#url' => Url::fromRoute('collection.leave_confirm_form', ['rdf_entity' => $collection->id()]), '#attributes' => ['class' => ['use-ajax', 'button', 'button--small', 'button--default', 'button--blue-light', 'mdl-button', 'mdl-js-button', 'mdl-button--raised', 'mdl-js-ripple-effect', 'mdl-button--accent'], 'data-dialog-type' => 'modal', 'data-dialog-options' => Json::encode(['width' => 'auto'])]]; $form['#attached']['library'][] = 'core/drupal.ajax'; } else { $form['join'] = ['#attributes' => ['class' => ['button--default', 'button--blue-light', 'mdl-button', 'mdl-js-button', 'mdl-button--raised', 'mdl-js-ripple-effect', 'mdl-button--accent']], '#type' => 'submit', '#value' => $this->t('Join this collection')]; } // This form varies by user and collection. // $metadata = new CacheableMetadata(); // $metadata // ->merge(CacheableMetadata::createFromObject($user)) // ->merge(CacheableMetadata::createFromObject($collection)) // ->applyTo($form); return $form; }
/** * {@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; }
/** * Returns a event content entity. * * @param \Drupal\rdf_entity\RdfInterface $rdf_entity * The parent that the event content entity belongs to. * * @return \Drupal\Core\Entity\EntityInterface * A node entity. */ protected function createEventEntity(RdfInterface $rdf_entity) { return $this->entityTypeManager()->getStorage('node')->create(['type' => 'event', OgGroupAudienceHelperInterface::DEFAULT_FIELD => $rdf_entity->id()]); }
/** * Route title callback. * * @param \Drupal\rdf_entity\RdfInterface $rdf_entity * The rdf entity. * * @return array * The rdf entity label as a render array. */ public function rdfTitle(RdfInterface $rdf_entity) { return ['#markup' => $rdf_entity->getName(), '#allowed_tags' => Xss::getHtmlTagList()]; }
/** * Creates a new asset_release entity. * * @param \Drupal\rdf_entity\RdfInterface $rdf_entity * The solution that the asset_release is version of. * * @return \Drupal\Core\Entity\EntityInterface * The unsaved asset_release entity. */ protected function createNewAssetRelease(RdfInterface $rdf_entity) { return $this->entityTypeManager()->getStorage('rdf_entity')->create(['rid' => 'asset_release', 'field_isr_is_version_of' => $rdf_entity->id()]); }