code/dataobjects/FusionTag.php
public function onAfterWrite() {

		parent::onAfterWrite();

		// Determine the tag types to update.

		$types = unserialize($this->TagTypes);
		$changed = $this->getChangedFields();
		foreach($this->service->getFusionTagTypes() as $type => $field) {
			if(isset($types[$type])) {

				// Determine whether new tag types exist.

				$newTypes = array();
				if(isset($changed['TagTypes'])) {
					$before = unserialize($changed['TagTypes']['before']);
					$after = unserialize($changed['TagTypes']['after']);
					$newTypes = is_array($before) ? array_diff($after, $before) : $after;
				}

				// Determine whether there's an existing tag.

				if((isset($changed['ID']) || isset($newTypes[$type])) && !($type::get()->filter($field, $this->Title)->first())) {

					// There is no tag, therefore instantiate one using this fusion tag.

					$tag = $type::create();
					$tag->$field = $this->Title;
					$tag->FusionTagID = $this->ID;
					$tag->write();
				}

				// Determine whether this fusion tag has been updated.

				else if(!isset($changed['ID']) && isset($changed['Title']) && ($existing = $type::get()->filter($field, $changed['Title']['before']))) {

					// There is an update, therefore update the existing tag/s to reflect the change.

					foreach($existing as $tag) {
						$tag->$field = $changed['Title']['after'];
						$tag->write();
					}
				}
			}
		}

		// Update the searchable content tagging for this fusion tag.

		if(!isset($changed['ID']) && isset($changed['Title'])) {
			$this->service->updateTagging($this->ID);
		}
	}
public function onAfterWrite() {

		parent::onAfterWrite();

		// Determine the tag types to update.

		$types = unserialize($this->TagTypes);
		$changed = $this->getChangedFields();
		foreach($this->service->getFusionTagTypes() as $type => $field) {
			if(isset($types[$type])) {

				// Determine whether new tag types exist.

				$newTypes = array();
				if(isset($changed['TagTypes'])) {
					$before = unserialize($changed['TagTypes']['before']);
					$after = unserialize($changed['TagTypes']['after']);
					$newTypes = is_array($before) ? array_diff($after, $before) : $after;
				}

				// Determine whether there's an existing tag.

				if((isset($changed['ID']) || isset($newTypes[$type])) && !($type::get()->filter($field, $this->Title)->first())) {

					// There is no tag, therefore instantiate one using this fusion tag.

					$tag = $type::create();
					$tag->$field = $this->Title;
					$tag->FusionTagID = $this->ID;
					$tag->write();
				}

				// Determine whether this fusion tag has been updated.

				else if(!isset($changed['ID']) && isset($changed['Title']) && ($existing = $type::get()->filter($field, $changed['Title']['before']))) {

					// There is an update, therefore update the existing tag/s to reflect the change.

					foreach($existing as $tag) {
						$tag->$field = $changed['Title']['after'];
						$tag->write();
					}
				}
			}
		}

		// Update the searchable content tagging for this fusion tag.

		if(!isset($changed['ID']) && isset($changed['Title'])) {
			$this->service->updateTagging($this->ID);
		}
	}
Update the existing and configuration defined tag types to reflect the change.