Added missing modules, including some as submodules.
[yaffs-website] / web / modules / contrib / linkit / src / Form / Matcher / DeleteForm.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\linkit\Form\Matcher\DeleteForm.
6  */
7
8 namespace Drupal\linkit\Form\Matcher;
9
10 use Drupal\Core\Form\ConfirmFormBase;
11 use Drupal\Core\Form\FormStateInterface;
12 use Drupal\Core\Url;
13 use Drupal\linkit\ProfileInterface;
14 use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
15
16 /**
17  * Provides a form to remove a matcher from a profile.
18  */
19 class DeleteForm extends ConfirmFormBase {
20
21   /**
22    * The profiles that the matcher is applied to.
23    *
24    * @var \Drupal\linkit\ProfileInterface
25    */
26   protected $linkitProfile;
27
28   /**
29    * The matcher to be removed from the profile.
30    *
31    * @var \Drupal\linkit\MatcherInterface
32    */
33   protected $linkitMatcher;
34
35   /**
36    * {@inheritdoc}
37    */
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()]);
40   }
41
42   /**
43    * {@inheritdoc}
44    */
45   public function getCancelUrl() {
46     return Url::fromRoute('linkit.matchers', [
47       'linkit_profile' => $this->linkitProfile->id(),
48     ]);
49   }
50
51   /**
52    * {@inheritdoc}
53    */
54   public function getFormId() {
55     return 'linkit_matcher_delete_form';
56   }
57
58   /**
59    * {@inheritdoc}
60    */
61   public function buildForm(array $form, FormStateInterface $form_state, ProfileInterface $linkit_profile = NULL, $plugin_instance_id = NULL) {
62     $this->linkitProfile = $linkit_profile;
63
64     if (!$this->linkitProfile->getMatchers()->has($plugin_instance_id)) {
65       throw new NotFoundHttpException();
66     }
67
68     $this->linkitMatcher = $this->linkitProfile->getMatcher($plugin_instance_id);
69     return parent::buildForm($form, $form_state);
70   }
71
72   /**
73    * {@inheritdoc}
74    */
75   public function submitForm(array &$form, FormStateInterface $form_state) {
76     $this->linkitProfile->removeMatcher($this->linkitMatcher);
77
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(),
82     ]);
83
84     $form_state->setRedirect('linkit.matchers', [
85       'linkit_profile' => $this->linkitProfile->id(),
86     ]);
87
88   }
89
90 }