You are here

class SuggestionCollection in Linkit 8.5

Defines a suggestion collection used to avoid JSON Hijacking.

Hierarchy

  • class \Drupal\linkit\Suggestion\SuggestionCollection implements \Drupal\linkit\Suggestion\JsonSerializable

Expanded class hierarchy of SuggestionCollection

6 files declare their use of SuggestionCollection
ConfigurableDummyMatcher.php in tests/linkit_test/src/Plugin/Linkit/Matcher/ConfigurableDummyMatcher.php
DummyMatcher.php in tests/linkit_test/src/Plugin/Linkit/Matcher/DummyMatcher.php
EmailMatcher.php in src/Plugin/Linkit/Matcher/EmailMatcher.php
EntityMatcher.php in src/Plugin/Linkit/Matcher/EntityMatcher.php
FrontPageMatcher.php in src/Plugin/Linkit/Matcher/FrontPageMatcher.php

... See full list

File

src/Suggestion/SuggestionCollection.php, line 8

Namespace

Drupal\linkit\Suggestion
View source
class SuggestionCollection implements \JsonSerializable {

  /**
   * An array of suggestions.
   *
   * @var array
   */
  protected $suggestions = [];

  /**
   * Returns all suggestions in the collection.
   *
   * @return \Drupal\linkit\Suggestion\SuggestionInterface[]
   *   All suggestions in the collection.
   */
  public function getSuggestions() {
    return $this->suggestions;
  }

  /**
   * Adds a suggestion to this collection.
   *
   * @param \Drupal\linkit\Suggestion\SuggestionInterface $suggestion
   *   The suggestion to add to the collection.
   */
  public function addSuggestion(SuggestionInterface $suggestion) {
    $this->suggestions[] = $suggestion;
  }

  /**
   * Adds a collection of suggestions to the this collection.
   *
   * @param \Drupal\linkit\Suggestion\SuggestionCollection $suggestionCollection
   *   A collection of suggestions.
   */
  public function addSuggestions(SuggestionCollection $suggestionCollection) {
    $this->suggestions = array_merge($this->suggestions, $suggestionCollection
      ->getSuggestions());
  }

  /**
   * {@inheritdoc}
   */
  public function jsonSerialize() {
    return [
      'suggestions' => $this->suggestions,
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SuggestionCollection::$suggestions protected property An array of suggestions.
SuggestionCollection::addSuggestion public function Adds a suggestion to this collection.
SuggestionCollection::addSuggestions public function Adds a collection of suggestions to the this collection.
SuggestionCollection::getSuggestions public function Returns all suggestions in the collection.
SuggestionCollection::jsonSerialize public function