/** * Test adding a configurable attribute to a profile. */ function testAddConfigurable() { $this->drupalGet(Url::fromRoute('linkit.matcher.add', [ 'linkit_profile' => $this->linkitProfile->id(), ])); $edit = array(); $edit['plugin'] = 'configurable_dummy_matcher'; $this->drupalPostForm(NULL, $edit, t('Save and continue')); // Load the saved profile. $this->linkitProfile = Profile::load($this->linkitProfile->id()); $matcher_ids = $this->linkitProfile->getMatchers()->getInstanceIds(); /** @var \Drupal\linkit\MatcherInterface $plugin */ $plugin = $this->linkitProfile->getMatcher(current($matcher_ids)); $this->assertUrl(Url::fromRoute('linkit.matcher.edit', [ 'linkit_profile' => $this->linkitProfile->id(), 'plugin_instance_id' => $plugin->getUuid(), ])); $this->drupalGet(Url::fromRoute('linkit.matchers', [ 'linkit_profile' => $this->linkitProfile->id(), ])); $this->assertNoText(t('No matchers added.')); }
/** * {@inheritdoc} */ public function form(array $form, FormStateInterface $form_state) { $form['label'] = [ '#type' => 'textfield', '#title' => $this->t('Profile Name'), '#default_value' => $this->entity->label(), '#description' => $this->t('The human-readable name of this profile. This name must be unique.'), '#required' => TRUE, '#size' => 30, ]; $form['id'] = [ '#type' => 'machine_name', '#default_value' => $this->entity->id(), '#machine_name' => [ 'exists' => ['\Drupal\linkit\Entity\Profile', 'load'] ], '#disabled' => !$this->entity->isNew(), ]; $form['description'] = [ '#type' => 'textarea', '#title' => $this->t('Description'), '#default_value' => $this->entity->getDescription(), '#description' => $this->t('The text will be displayed on the <em>profile collection</em> page.'), ]; $form['additional_settings'] = array( '#type' => 'vertical_tabs', '#weight' => 99, ); return parent::form($form, $form_state); }
/** * Tests the attribute route title callback. */ function testAttributeTitle() { /** @var \Drupal\linkit\AttributeInterface $plugin */ $plugin = $this->container->get('plugin.manager.linkit.attribute')->createInstance('configurable_dummy_attribute'); $this->linkitProfile->addAttribute($plugin->getConfiguration()); $this->linkitProfile->save(); $this->drupalGet(Url::fromRoute('linkit.attribute.edit', [ 'linkit_profile' => $this->linkitProfile->id(), 'plugin_instance_id' => $plugin->getPluginId(), ])); $this->assertText('Edit ' . $plugin->getLabel() . ' attribute'); }
/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { $this->linkitProfile->removeMatcher($this->linkitMatcher); drupal_set_message($this->t('The matcher %label has been deleted.', ['%label' => $this->linkitMatcher->getLabel()])); $this->logger('linkit')->notice('The matcher %label has been deleted in the @profile profile.', [ '%label' => $this->linkitMatcher->getLabel(), '@profile' => $this->linkitProfile->label(), ]); $form_state->setRedirect('linkit.matchers', [ 'linkit_profile' => $this->linkitProfile->id(), ]); }
/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { $form_state->cleanValues(); /** @var \Drupal\linkit\MatcherInterface $plugin */ $plugin = $this->manager->createInstance($form_state->getValue('plugin')); $plugin_uuid = $this->linkitProfile->addMatcher($plugin->getConfiguration()); $this->linkitProfile->save(); $this->logger('linkit')->notice('Added %label matcher to the @profile profile.', [ '%label' => $this->linkitProfile->getMatcher($plugin_uuid)->getLabel(), '@profile' => $this->linkitProfile->label(), ]); $is_configurable = $plugin instanceof ConfigurableMatcherInterface; if ($is_configurable) { $form_state->setRedirect('linkit.matcher.edit', [ 'linkit_profile' => $this->linkitProfile->id(), 'plugin_instance_id' => $plugin_uuid, ]); } else { drupal_set_message($this->t('Added %label matcher.', ['%label' => $plugin->getLabel()])); $form_state->setRedirect('linkit.matchers', [ 'linkit_profile' => $this->linkitProfile->id(), ]); } }
/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { $form_state->cleanValues(); $plugin_data = (new FormState())->setValues($form_state->getValues()); $this->linkitMatcher->submitConfigurationForm($form, $plugin_data); $this->linkitProfile->save(); drupal_set_message($this->t('Saved %label configuration.', array('%label' => $this->linkitMatcher->getLabel()))); $this->logger('linkit')->notice('The matcher %label has been updated in the @profile profile.', [ '%label' => $this->linkitMatcher->getLabel(), '@profile' => $this->linkitProfile->label(), ]); $form_state->setRedirect('linkit.matchers', [ 'linkit_profile' => $this->linkitProfile->id(), ]); }
/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { if ($this->linkitProfile->getAttributes()->has($this->linkitAttribute->getPluginId())) { $this->linkitProfile->removeAttribute($this->linkitAttribute->getPluginId()); $this->linkitProfile->save(); drupal_set_message($this->t('The attribute %label has been deleted.', ['%label' => $this->linkitAttribute->getLabel()])); $this->logger('linkit')->notice('The attribute %label has been deleted in the @profile profile.', [ '%label' => $this->linkitAttribute->getLabel(), '@profile' => $this->linkitProfile->label(), ]); } $form_state->setRedirect('linkit.attributes', [ 'linkit_profile' => $this->linkitProfile->id(), ]); }
/** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state, ProfileInterface $linkit_profile = NULL) { $this->linkitProfile = $linkit_profile; $form['#attached']['library'][] = 'linkit/linkit.admin'; $form['plugins'] = [ '#type' => 'table', '#header' => [ [ 'data' => $this->t('Matcher'), 'colspan' => 2 ], $this->t('Weight'), $this->t('Operations'), ], '#empty' => $this->t('No matchers added.'), '#tabledrag' => [ [ 'action' => 'order', 'relationship' => 'sibling', 'group' => 'plugin-order-weight', ], ], ]; foreach ($this->linkitProfile->getMatchers() as $plugin) { $key = $plugin->getUuid(); $form['plugins'][$key]['#attributes']['class'][] = 'draggable'; $form['plugins'][$key]['#weight'] = $plugin->getWeight(); $form['plugins'][$key]['label'] = [ '#plain_text' => (string) $plugin->getLabel(), ]; $form['plugins'][$key]['summary'] = []; $summary = $plugin->getSummary(); if (!empty($summary)) { $form['plugins'][$key]['summary'] = [ '#type' => 'inline_template', '#template' => '<div class="linkit-plugin-summary">{{ summary|safe_join("<br />") }}</div>', '#context' => ['summary' => $summary], ]; } $form['plugins'][$key]['weight'] = [ '#type' => 'weight', '#title' => t('Weight for @title', ['@title' => (string) $plugin->getLabel()]), '#title_display' => 'invisible', '#default_value' => $plugin->getWeight(), '#attributes' => ['class' => ['plugin-order-weight']], ]; $form['plugins'][$key]['operations'] = [ '#type' => 'operations', '#links' => [], ]; $is_configurable = $plugin instanceof ConfigurableMatcherInterface; if ($is_configurable) { $form['plugins'][$key]['operations']['#links']['edit'] = [ 'title' => t('Edit'), 'url' => Url::fromRoute('linkit.matcher.edit', [ 'linkit_profile' => $this->linkitProfile->id(), 'plugin_instance_id' => $key, ]), ]; } $form['plugins'][$key]['operations']['#links']['delete'] = [ 'title' => t('Delete'), 'url' => Url::fromRoute('linkit.matcher.delete', [ 'linkit_profile' => $this->linkitProfile->id(), 'plugin_instance_id' => $key, ]), ]; } $form['actions'] = ['#type' => 'actions']; $form['actions']['submit'] = [ '#type' => 'submit', '#value' => $this->t('Save'), '#button_type' => 'primary', ]; return $form; }
/** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state, ProfileInterface $linkit_profile = NULL) { $this->linkitProfile = $linkit_profile; $form['plugins'] = [ '#type' => 'table', '#header' => [ $this->t('Attribute'), $this->t('Description'), $this->t('Weight'), $this->t('Operations'), ], '#empty' => $this->t('No attributes added.'), '#tabledrag' => [ [ 'action' => 'order', 'relationship' => 'sibling', 'group' => 'plugin-order-weight', ], ], ]; foreach ($this->linkitProfile->getAttributes() as $plugin) { $key = $plugin->getPluginId(); $form['plugins'][$key]['#attributes']['class'][] = 'draggable'; $form['plugins'][$key]['#weight'] = $plugin->getWeight(); $form['plugins'][$key]['label'] = [ '#plain_text' => (string) $plugin->getLabel(), ]; $form['plugins'][$key]['description'] = [ '#plain_text' => (string) $plugin->getDescription(), ]; $form['plugins'][$key]['weight'] = [ '#type' => 'weight', '#title' => t('Weight for @title', ['@title' => (string) $plugin->getLabel()]), '#title_display' => 'invisible', '#default_value' => $plugin->getWeight(), '#attributes' => ['class' => ['plugin-order-weight']], ]; $form['plugins'][$key]['operations'] = [ '#type' => 'operations', '#links' => [], ]; $is_configurable = $plugin instanceof ConfigurableAttributeInterface; if ($is_configurable) { $form['plugins'][$key]['operations']['#links']['edit'] = [ 'title' => t('Edit'), 'url' => Url::fromRoute('linkit.attribute.edit', [ 'linkit_profile' => $this->linkitProfile->id(), 'plugin_instance_id' => $key, ]), ]; } $form['plugins'][$key]['operations']['#links']['delete'] = [ 'title' => t('Delete'), 'url' => Url::fromRoute('linkit.attribute.delete', [ 'linkit_profile' => $this->linkitProfile->id(), 'plugin_instance_id' => $key, ]), ]; } $form['actions'] = ['#type' => 'actions']; $form['actions']['submit'] = [ '#type' => 'submit', '#value' => $this->t('Save'), '#button_type' => 'primary', ]; return $form; }