/** * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { parent::validateForm($form, $form_state); // Only authenticated users can leave a collection. /** @var \Drupal\user\UserInterface $user */ $user = User::load($this->currentUser()->id()); if ($user->isAnonymous()) { $form_state->setErrorByName('user', $this->t('<a href=":login">Log in</a> or <a href=":register">register</a> to change your group membership.', [':login' => Url::fromRoute('user.login'), ':register' => Url::fromRoute('user.register')])); } // Check if the user is a member of the collection. if (!Og::isMember($this->collection, $user)) { $form_state->setErrorByName('collection', $this->t('You are not a member of this collection. You cannot leave it.')); } }
/** * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { parent::validateForm($form, $form_state); }