Added missing modules, including some as submodules.
[yaffs-website] / web / modules / contrib / linkit / src / Form / Attribute / DeleteForm.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\linkit\Form\Attribute\DeleteForm.
6  */
7
8 namespace Drupal\linkit\Form\Attribute;
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 an attribute from a profile.
18  */
19 class DeleteForm extends ConfirmFormBase {
20
21   /**
22    * The profiles that the attribute is applied to.
23    *
24    * @var \Drupal\linkit\ProfileInterface
25    */
26   protected $linkitProfile;
27
28   /**
29    * The attribute to be removed from the profile.
30    *
31    * @var \Drupal\linkit\AttributeInterface
32    */
33   protected $linkitAttribute;
34
35   /**
36    * {@inheritdoc}
37    */
38   public function getQuestion() {
39     return $this->t('Are you sure you want to delete the @plugin attribute from the %profile profile?', ['%profile' => $this->linkitProfile->label(), '@plugin' => $this->linkitAttribute->getLabel()]);
40   }
41
42   /**
43    * {@inheritdoc}
44    */
45   public function getCancelUrl() {
46     return Url::fromRoute('linkit.attributes', [
47       'linkit_profile' => $this->linkitProfile->id(),
48     ]);
49   }
50
51   /**
52    * {@inheritdoc}
53    */
54   public function getFormId() {
55     return 'linkit_attribute_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->getAttributes()->has($plugin_instance_id)) {
65       throw new NotFoundHttpException();
66     }
67
68     $this->linkitAttribute = $this->linkitProfile->getAttribute($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     if ($this->linkitProfile->getAttributes()->has($this->linkitAttribute->getPluginId())) {
77       $this->linkitProfile->removeAttribute($this->linkitAttribute->getPluginId());
78       $this->linkitProfile->save();
79
80       drupal_set_message($this->t('The attribute %label has been deleted.', ['%label' => $this->linkitAttribute->getLabel()]));
81       $this->logger('linkit')->notice('The attribute %label has been deleted in the @profile profile.', [
82         '%label' => $this->linkitAttribute->getLabel(),
83         '@profile' => $this->linkitProfile->label(),
84       ]);
85     }
86
87     $form_state->setRedirect('linkit.attributes', [
88       'linkit_profile' => $this->linkitProfile->id(),
89     ]);
90   }
91
92 }