TeamInvitationResendForm.php in Apigee Edge 8
File
modules/apigee_edge_teams/src/Entity/Form/TeamInvitationResendForm.php
View source
<?php
namespace Drupal\apigee_edge_teams\Entity\Form;
use Drupal\apigee_edge_teams\Entity\TeamInvitationInterface;
use Drupal\apigee_edge_teams\TeamInvitationNotifierInterface;
use Drupal\Component\Datetime\TimeInterface;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Entity\EntityRepositoryInterface;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class TeamInvitationResendForm extends TeamInvitationFormBase {
protected $teamInvitationNotifier;
public function __construct(EntityRepositoryInterface $entity_repository, EntityTypeBundleInfoInterface $entity_type_bundle_info, TimeInterface $time, TeamInvitationNotifierInterface $team_invitation_notifier) {
parent::__construct($entity_repository, $entity_type_bundle_info, $time);
$this->teamInvitationNotifier = $team_invitation_notifier;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('entity.repository'), $container
->get('entity_type.bundle.info'), $container
->get('datetime.time'), $container
->get('apigee_edge_teams.team_invitation_notifier.email'));
}
public function getQuestion() {
return $this
->t('Are you sure you want to resend the %label to %recipient?', [
'%label' => $this
->getEntity()
->label(),
'%recipient' => $this
->getEntity()
->getRecipient(),
]);
}
public function getConfirmText() {
return $this
->t('Resend invitation');
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$team_invitation = $this->entity;
$team_invitation
->setStatus(TeamInvitationInterface::STATUS_PENDING);
$days = $this
->config('apigee_edge_teams.team_settings')
->get('team_invitation_expiry_days');
$team_invitation
->setExpiryTime($this->time
->getCurrentTime() + 24 * 60 * 60 * (int) $days);
$team_invitation
->save();
if ($this->teamInvitationNotifier
->sendNotificationsFor($team_invitation)) {
$this
->messenger()
->addMessage($this
->t('The invitation to join the %team team has been resent to %recipient.', [
'%team' => $team_invitation
->getTeam()
->label(),
'%recipient' => $team_invitation
->getRecipient(),
]));
}
$form_state
->setRedirectUrl($this->team
->toUrl('members'));
}
}