5 * Contains \Drupal\linkit\Form\Matcher\OverviewForm.
8 namespace Drupal\linkit\Form\Matcher;
10 use Drupal\Core\Form\FormBase;
11 use Drupal\Core\Form\FormStateInterface;
13 use Drupal\linkit\ConfigurableMatcherInterface;
14 use Drupal\linkit\MatcherManager;
15 use Drupal\linkit\ProfileInterface;
16 use Symfony\Component\DependencyInjection\ContainerInterface;
19 * Provides an overview form for matchers on a profile.
21 class OverviewForm extends FormBase {
24 * The profiles to which the matchers are applied to.
26 * @var \Drupal\linkit\ProfileInterface
28 private $linkitProfile;
31 * The matcher manager.
33 * @var \Drupal\linkit\MatcherManager
38 * Constructs a new OverviewForm.
40 * @param \Drupal\linkit\MatcherManager $manager
41 * The matcher manager.
43 public function __construct(MatcherManager $manager) {
44 $this->manager = $manager;
50 public static function create(ContainerInterface $container) {
52 $container->get('plugin.manager.linkit.matcher')
59 public function getFormId() {
60 return "linkit_matcher_overview_form";
66 public function buildForm(array $form, FormStateInterface $form_state, ProfileInterface $linkit_profile = NULL) {
67 $this->linkitProfile = $linkit_profile;
68 $form['#attached']['library'][] = 'linkit/linkit.admin';
73 'data' => $this->t('Matcher'),
77 $this->t('Operations'),
79 '#empty' => $this->t('No matchers added.'),
83 'relationship' => 'sibling',
84 'group' => 'plugin-order-weight',
89 foreach ($this->linkitProfile->getMatchers() as $plugin) {
90 $key = $plugin->getUuid();
92 $form['plugins'][$key]['#attributes']['class'][] = 'draggable';
93 $form['plugins'][$key]['#weight'] = $plugin->getWeight();
95 $form['plugins'][$key]['label'] = [
96 '#plain_text' => (string) $plugin->getLabel(),
99 $form['plugins'][$key]['summary'] = [];
101 $summary = $plugin->getSummary();
102 if (!empty($summary)) {
103 $form['plugins'][$key]['summary'] = [
104 '#type' => 'inline_template',
105 '#template' => '<div class="linkit-plugin-summary">{{ summary|safe_join("<br />") }}</div>',
106 '#context' => ['summary' => $summary],
110 $form['plugins'][$key]['weight'] = [
112 '#title' => t('Weight for @title', ['@title' => (string) $plugin->getLabel()]),
113 '#title_display' => 'invisible',
114 '#default_value' => $plugin->getWeight(),
115 '#attributes' => ['class' => ['plugin-order-weight']],
118 $form['plugins'][$key]['operations'] = [
119 '#type' => 'operations',
123 $is_configurable = $plugin instanceof ConfigurableMatcherInterface;
124 if ($is_configurable) {
125 $form['plugins'][$key]['operations']['#links']['edit'] = [
126 'title' => t('Edit'),
127 'url' => Url::fromRoute('linkit.matcher.edit', [
128 'linkit_profile' => $this->linkitProfile->id(),
129 'plugin_instance_id' => $key,
134 $form['plugins'][$key]['operations']['#links']['delete'] = [
135 'title' => t('Delete'),
136 'url' => Url::fromRoute('linkit.matcher.delete', [
137 'linkit_profile' => $this->linkitProfile->id(),
138 'plugin_instance_id' => $key,
143 $form['actions'] = ['#type' => 'actions'];
144 $form['actions']['submit'] = [
146 '#value' => $this->t('Save'),
147 '#button_type' => 'primary',
156 public function submitForm(array &$form, FormStateInterface $form_state) {
157 foreach ($form_state->getValue('plugins') as $id => $plugin_data) {
158 if ($this->linkitProfile->getMatchers()->has($id)) {
159 $this->linkitProfile->getMatcher($id)->setWeight($plugin_data['weight']);
162 $this->linkitProfile->save();