You are here

class NewTermStorage in Super Term Reference Autocomplete Widget 8

Stores terms which have been created by Straw but not yet saved by Drupal.

Hierarchy

Expanded class hierarchy of NewTermStorage

1 string reference to 'NewTermStorage'
straw.services.yml in ./straw.services.yml
straw.services.yml
1 service uses NewTermStorage
straw.new_term_storage in ./straw.services.yml
Drupal\straw\NewTermStorage

File

src/NewTermStorage.php, line 10

Namespace

Drupal\straw
View source
class NewTermStorage {

  /**
   * The term storage.
   *
   * This is stored as an array of vocabulary names, each of which contains an
   * array with keys of the term hierarchy and values of the created Term object
   * which will eventually get saved.
   *
   * @var array
   */
  protected $termStorage;

  /**
   * Gets a term from the storage, or NULL if it doesn't exist.
   *
   * @param string $bundle
   *   The vocabulary in which to check for the term.
   * @param string $tree_path
   *   A string containing the hierarchy of what term to look up.
   *
   * @return \Drupal\taxonomy\Entity\Term|null
   *   The stored term.
   */
  public function get($bundle, $tree_path) {
    return $this->termStorage[$bundle][$tree_path] ?? NULL;
  }

  /**
   * Adds a new term to the storage.
   *
   * @param string $bundle
   *   The vocabulary the term will be a part of.
   * @param string $tree_path
   *   A string containing the hierarchy of where the term will exist once it is
   *   created.
   * @param \Drupal\taxonomy\Entity\Term $term
   *   The newly created term.
   */
  public function set($bundle, $tree_path, Term $term) {
    $this->termStorage[$bundle][$tree_path] = $term;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
NewTermStorage::$termStorage protected property The term storage.
NewTermStorage::get public function Gets a term from the storage, or NULL if it doesn't exist.
NewTermStorage::set public function Adds a new term to the storage.