Skip to content
Snippets Groups Projects

3102570: Store static reference of replaced term ids.

1 file
+ 50
1
Compare changes
  • Side-by-side
  • Inline
+ 50
1
@@ -76,6 +76,54 @@ abstract class GlossifyBase extends FilterBase implements ContainerFactoryPlugin
);
}
/**
* Retrieves a static reference to an array of replaced term IDs for a given plugin type.
*
* This method ensures that the stored term IDs persist across multiple
* calls within the same request.
*
* @param string $pluginId
* The implementation plugin id.
*
* @return array
* A reference to an array containing the replaced term IDs associated with plugin id.
*/
protected function &getReplacedTermsIds($pluginId) {
$staticKey = __METHOD__ . ':' . $pluginId;
return drupal_static($staticKey, []);
}
/**
* Append replaced term id to the static reference of replaced term ids.
*
* @param string $term_id
* The term id to append.
*
* @return bool
* Whether the term id was appended.
*/
public function AddReplacedTermId(string $term_id) {
$term_ids = &$this->getReplacedTermsIds($this->getPluginId());
if ($this->hasReplacedTermId($term_id)) {
return FALSE;
}
$term_ids[] = $term_id;
return TRUE;
}
/**
* Check that current term id has already been replaced in the current request.
*
* @param string $term_id
* The concerning term id.
*
* @return bool
* Whether the term id has already been replaced.
*/
public function hasReplacedTermId(string $term_id) {
return in_array($term_id, $this->getReplacedTermsIds($this->getPluginId()));
}
/**
* Convert terms in text to links.
*
@@ -233,7 +281,7 @@ abstract class GlossifyBase extends FilterBase implements ContainerFactoryPlugin
// to.
$replacementTextOrHtml = $term_txt;
}
elseif ($first_only && in_array(strtolower($term_txt), array_map('strtolower', ($replaced)))) {
elseif ($first_only && (in_array(strtolower($term_txt), array_map('strtolower', ($replaced))) || $this->hasReplacedTermId($term->id))) {
// Reinsert the found match if only first match must be parsed.
$replacementTextOrHtml = $term_txt;
}
@@ -280,6 +328,7 @@ abstract class GlossifyBase extends FilterBase implements ContainerFactoryPlugin
}
$replaced[] = $term_txt;
$this->AddReplacedTermId($term->id);
}
// Insert the replacment back into the DOM. There's no appendHTML
Loading