5 * Contains \Drupal\linkit\Form\Matcher\DeleteForm.
8 namespace Drupal\linkit\Form\Matcher;
10 use Drupal\Core\Form\ConfirmFormBase;
11 use Drupal\Core\Form\FormStateInterface;
13 use Drupal\linkit\ProfileInterface;
14 use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
17 * Provides a form to remove a matcher from a profile.
19 class DeleteForm extends ConfirmFormBase {
22 * The profiles that the matcher is applied to.
24 * @var \Drupal\linkit\ProfileInterface
26 protected $linkitProfile;
29 * The matcher to be removed from the profile.
31 * @var \Drupal\linkit\MatcherInterface
33 protected $linkitMatcher;
38 public function getQuestion() {
39 return $this->t('Are you sure you want to delete the @plugin matcher from the %profile profile?', ['%profile' => $this->linkitProfile->label(), '@plugin' => $this->linkitMatcher->getLabel()]);
45 public function getCancelUrl() {
46 return Url::fromRoute('linkit.matchers', [
47 'linkit_profile' => $this->linkitProfile->id(),
54 public function getFormId() {
55 return 'linkit_matcher_delete_form';
61 public function buildForm(array $form, FormStateInterface $form_state, ProfileInterface $linkit_profile = NULL, $plugin_instance_id = NULL) {
62 $this->linkitProfile = $linkit_profile;
64 if (!$this->linkitProfile->getMatchers()->has($plugin_instance_id)) {
65 throw new NotFoundHttpException();
68 $this->linkitMatcher = $this->linkitProfile->getMatcher($plugin_instance_id);
69 return parent::buildForm($form, $form_state);
75 public function submitForm(array &$form, FormStateInterface $form_state) {
76 $this->linkitProfile->removeMatcher($this->linkitMatcher);
78 drupal_set_message($this->t('The matcher %label has been deleted.', ['%label' => $this->linkitMatcher->getLabel()]));
79 $this->logger('linkit')->notice('The matcher %label has been deleted in the @profile profile.', [
80 '%label' => $this->linkitMatcher->getLabel(),
81 '@profile' => $this->linkitProfile->label(),
84 $form_state->setRedirect('linkit.matchers', [
85 'linkit_profile' => $this->linkitProfile->id(),