示例#1
0
  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state, ProfileInterface $linkit_profile = NULL, $plugin_instance_id = NULL) {
    $this->linkitProfile = $linkit_profile;

    if (!$this->linkitProfile->getMatchers()->has($plugin_instance_id)) {
      throw new NotFoundHttpException();
    }

    $this->linkitMatcher = $this->linkitProfile->getMatcher($plugin_instance_id);
    return parent::buildForm($form, $form_state);
  }
示例#2
0
  /**
   * 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.'));
  }
示例#3
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state) {
   foreach ($form_state->getValue('plugins') as $id => $plugin_data) {
     if ($this->linkitProfile->getMatchers()->has($id)) {
       $this->linkitProfile->getMatcher($id)->setWeight($plugin_data['weight']);
     }
   }
   $this->linkitProfile->save();
 }
示例#4
0
  /**
   * Gets the results.
   *
   * @param ProfileInterface $linkitProfile
   *   The linkit profile.
   * @param $search_string
   *   The string ro use in the matchers.
   *
   * @return array
   *   An array of matches.
   */
  public function getResults(ProfileInterface $linkitProfile, $search_string) {
    $matches = array();

    if (empty(trim($search_string))) {
      return [[
        'title' => t('No results'),
      ]];
    }

    // Special for link to front page.
    if (strpos($search_string, 'front') !== FALSE) {
      $matches[] = [
        'title' => t('Front page'),
        'description' => 'The front page for this site.',
        'path' => Url::fromRoute('<front>')->toString(),
        'group' => t('System'),
      ];
    }

    foreach ($linkitProfile->getMatchers() as $plugin) {
      $matches = array_merge($matches, $plugin->getMatches($search_string));
    }

    // Check for an e-mail address then return an e-mail match and create a
    // mail-to link if appropriate.
    if (filter_var($search_string, FILTER_VALIDATE_EMAIL)) {
      $matches[] = [
        'title' => t('E-mail @email', ['@email' => $search_string]),
        'description' => t('Opens your mail client ready to e-mail @email', ['@email' => $search_string]),
        'path' => 'mailto:' . Html::escape($search_string),
        'group' => t('E-mail'),
      ];
    }

    // If there is still no matches, return a "no results" array.
    if (empty($matches)) {
      return [[
        'title' => t('No results'),
      ]];
    }

    return $matches;
  }