193d3263d309cf66cf84d1d4e3cd16458ff6699d
[yaffs-website] / web / modules / contrib / linkit / src / Form / Matcher / EditForm.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\linkit\Form\Matcher\EditForm.
6  */
7
8 namespace Drupal\linkit\Form\Matcher;
9
10 use Drupal\Core\Form\FormBase;
11 use Drupal\Core\Form\FormState;
12 use Drupal\Core\Form\FormStateInterface;
13 use Drupal\Core\Url;
14 use Drupal\linkit\ProfileInterface;
15
16 /**
17  *  Provides an edit form for matchers.
18  */
19 class EditForm extends FormBase {
20
21   /**
22    * The profiles to which the matchers will be applied.
23    *
24    * @var \Drupal\linkit\ProfileInterface
25    */
26   protected $linkitProfile;
27
28   /**
29    * The matcher to edit.
30    *
31    * @var \Drupal\linkit\ConfigurableMatcherInterface
32    */
33   protected $linkitMatcher;
34
35   /**
36    * {@inheritdoc}
37    */
38   public function getFormId() {
39     return 'linkit_matcher_edit_form';
40   }
41
42   /**
43    * {@inheritdoc}
44    */
45   public function buildForm(array $form, FormStateInterface $form_state, ProfileInterface $linkit_profile = NULL, $plugin_instance_id = NULL) {
46     $this->linkitProfile = $linkit_profile;
47     $this->linkitMatcher = $this->linkitProfile->getMatcher($plugin_instance_id);
48
49     $form += $this->linkitMatcher->buildConfigurationForm($form, $form_state);
50
51     $form['actions'] = array('#type' => 'actions');
52     $form['actions']['submit'] = array(
53       '#type' => 'submit',
54       '#value' => $this->t('Save changes'),
55       '#submit' => array('::submitForm'),
56       '#button_type' => 'primary',
57     );
58     $form['actions']['delete'] = array(
59       '#type' => 'link',
60       '#title' => $this->t('Delete'),
61       '#url' => Url::fromRoute('linkit.matcher.delete', [
62         'linkit_profile' => $this->linkitProfile->id(),
63         'plugin_instance_id' => $this->linkitMatcher->getUuid(),
64       ]),
65       '#attributes' => [
66         'class' => ['button', 'button--danger'],
67       ],
68     );
69
70     return $form;
71   }
72
73   /**
74    * {@inheritdoc}
75    */
76   public function submitForm(array &$form, FormStateInterface $form_state) {
77     $form_state->cleanValues();
78     $plugin_data = (new FormState())->setValues($form_state->getValues());
79     $this->linkitMatcher->submitConfigurationForm($form, $plugin_data);
80     $this->linkitProfile->save();
81
82     drupal_set_message($this->t('Saved %label configuration.', array('%label' => $this->linkitMatcher->getLabel())));
83     $this->logger('linkit')->notice('The matcher %label has been updated in the @profile profile.', [
84       '%label' => $this->linkitMatcher->getLabel(),
85       '@profile' => $this->linkitProfile->label(),
86     ]);
87
88     $form_state->setRedirect('linkit.matchers', [
89       'linkit_profile' => $this->linkitProfile->id(),
90     ]);
91   }
92 }