<?php namespace ProcessWire;

/**
 * ProcessWire Title Fieldtype
 *
 * Field that holds a Page title 
 *
 * For documentation about the fields used in this class, please see:  
 * /wire/core/Fieldtype.php
 * 
 * ProcessWire 3.x, Copyright 2022 by Ryan Cramer
 * https://processwire.com
 *
 *
 */

class FieldtypePageTitle extends FieldtypeText implements FieldtypePageTitleCompatible {

	public static function getModuleInfo() {
		return array(
			'title' => 'Page Title',
			'version' => 100,
			'summary' => 'Field that stores a page title',
			'permanent' => true, 
		);
	}

	/**
	 * This field is only used for new fields in advanced mode
	 *
	 */
	public function isAdvanced() {
		return true; 
	}

	/**
	 * Sanitize value for storage
	 *
	 * @param Page $page
	 * @param Field $field
	 * @param string $value
	 * @return string
	 *
	 */
	public function sanitizeValue(Page $page, Field $field, $value) {
		if(is_string($value)) $value = trim($value);
		return $value;
	}

	/**
	 * Get compatible Fieldtypes
	 * 
	 * @param Field $field
	 * @return Fieldtypes
	 * 
	 */
	public function ___getCompatibleFieldtypes(Field $field) {
		$fieldtypes = $this->wire(new Fieldtypes());
		foreach($this->wire()->fieldtypes as $fieldtype) {
			if($fieldtype instanceof FieldtypePageTitleCompatible) {
				$fieldtypes->add($fieldtype);
			}
		}
		return $fieldtypes;
	}

	/**
	 * Get Inputfield
	 * 
	 * @param Page $page
	 * @param Field $field
	 * @return Inputfield|InputfieldPageTitle
	 * 
	 */
	public function getInputfield(Page $page, Field $field) {
		/** @var InputfieldPageTitle $inputField */
		$inputField = $this->modules->get('InputfieldPageTitle'); 
		return $inputField; 
	}

	/**
	 * True when language support is active, false if not
	 *
	 * Set by LanguageSupport.module to true during LanguageSupport::init()
	 *
	 * @var bool
	 * @deprecated No longer in use
	 *
	 */
	public static $languageSupport = false;

}

