public function onBeforeWrite() {

		parent::onBeforeWrite();

		// Determine whether new tag types exist.

		$types = $this->Types ? explode(',', $this->Types) : array();

		// Merge the new and existing tag types.

		if(is_string($this->TagTypes)) {
			$types = array_merge($types, array_keys(unserialize($this->TagTypes)));
		}
		if(!empty($types)) {
			sort($types);

			// Update the tag types with a serialised representation.

			$formatted = array();
			$existing = $this->service->getFusionTagTypes();
			foreach($types as $type) {

				// The tag type exclusions need checking.

				if(isset($existing[$type])) {
					$formatted[$type] = $type;
				}
			}
			$this->TagTypes = !empty($formatted) ? serialize($formatted) : null;

			// Update the custom field to reflect the change correctly.

			$this->Types = implode(',', $formatted);
		}
	}