5 * Contains \Drupal\linkit\Form\Matcher\EditForm.
8 namespace Drupal\linkit\Form\Matcher;
10 use Drupal\Core\Form\FormBase;
11 use Drupal\Core\Form\FormState;
12 use Drupal\Core\Form\FormStateInterface;
14 use Drupal\linkit\ProfileInterface;
17 * Provides an edit form for matchers.
19 class EditForm extends FormBase {
22 * The profiles to which the matchers will be applied.
24 * @var \Drupal\linkit\ProfileInterface
26 protected $linkitProfile;
29 * The matcher to edit.
31 * @var \Drupal\linkit\ConfigurableMatcherInterface
33 protected $linkitMatcher;
38 public function getFormId() {
39 return 'linkit_matcher_edit_form';
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);
49 $form += $this->linkitMatcher->buildConfigurationForm($form, $form_state);
51 $form['actions'] = array('#type' => 'actions');
52 $form['actions']['submit'] = array(
54 '#value' => $this->t('Save changes'),
55 '#submit' => array('::submitForm'),
56 '#button_type' => 'primary',
58 $form['actions']['delete'] = array(
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(),
66 'class' => ['button', 'button--danger'],
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();
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(),
88 $form_state->setRedirect('linkit.matchers', [
89 'linkit_profile' => $this->linkitProfile->id(),