Пример #1
0
 /**
  * Returns the OgRole objects identified by the given role names.
  *
  * @param array $roles
  *    An array of role names for which to return the roles.
  * @param \Drupal\Core\Entity\EntityInterface $group
  *    The group entity to which the roles belong.
  *
  * @return \Drupal\og\Entity\OgRole[]
  *    The OgRole objects.
  */
 protected function getOgRoles(array $roles, EntityInterface $group)
 {
     $ids = $this->convertOgRoleNamesToIds($roles, $group);
     return array_values(OgRole::loadMultiple($ids));
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     /** @var RdfInterface $collection */
     $collection = Rdf::load($form_state->getValue('collection_id'));
     /** @var \Drupal\user\UserInterface $user */
     $user = User::load($form_state->getValue('user_id'));
     $role_id = $collection->getEntityTypeId() . '-' . $collection->bundle() . '-' . OgRoleInterface::AUTHENTICATED;
     $membership = OgMembership::create();
     $membership->setUser($user)->setGroup($collection)->setState(OgMembershipInterface::STATE_ACTIVE)->setRoles([OgRole::load($role_id)])->save();
     drupal_set_message($this->t('You are now a member of %collection.', ['%collection' => $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']);
 }