5 * Contains \Drupal\linkit\Form\Attribute\DeleteForm.
8 namespace Drupal\linkit\Form\Attribute;
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 an attribute from a profile.
19 class DeleteForm extends ConfirmFormBase {
22 * The profiles that the attribute is applied to.
24 * @var \Drupal\linkit\ProfileInterface
26 protected $linkitProfile;
29 * The attribute to be removed from the profile.
31 * @var \Drupal\linkit\AttributeInterface
33 protected $linkitAttribute;
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()]);
45 public function getCancelUrl() {
46 return Url::fromRoute('linkit.attributes', [
47 'linkit_profile' => $this->linkitProfile->id(),
54 public function getFormId() {
55 return 'linkit_attribute_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->getAttributes()->has($plugin_instance_id)) {
65 throw new NotFoundHttpException();
68 $this->linkitAttribute = $this->linkitProfile->getAttribute($plugin_instance_id);
69 return parent::buildForm($form, $form_state);
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();
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(),
87 $form_state->setRedirect('linkit.attributes', [
88 'linkit_profile' => $this->linkitProfile->id(),