'Page Name',
'version' => 106,
'summary' => 'Text input validated as a ProcessWire Page name field',
'permanent' => true,
);
}
public static $defaultReplacements = array(
'æ' => 'ae',
'å' => 'a',
'ä' => 'a',
'ã' => 'a',
'ß' => 'ss',
'ö' => 'o',
'ü' => 'u',
'đ' => 'dj',
'ж' => 'zh',
'х' => 'kh',
'ц' => 'tc',
'ч' => 'ch',
'ш' => 'sh',
'щ' => 'shch',
'ю' => 'iu',
'я' => 'ia',
':' => '-',
',' => '-',
'à' => 'a',
'á' => 'a',
'â' => 'a',
'è' => 'e',
'é' => 'e',
'ë' => 'e',
'ê' => 'e',
'ě' => 'e',
'ì' => 'i',
'í' => 'i',
'ï' => 'i',
'î' => 'i',
'ı' => 'i',
'İ' => 'i',
'ğ' => 'g',
'õ' => 'o',
'ò' => 'o',
'ó' => 'o',
'ô' => 'o',
'ø' => 'o',
'ù' => 'u',
'ú' => 'u',
'û' => 'u',
'ů' => 'u',
'ñ' => 'n',
'ç' => 'c',
'č' => 'c',
'ć' => 'c',
'Ç' => 'c',
'ď' => 'd',
'ĺ' => 'l',
'ľ' => 'l',
'ń' => 'n',
'ň' => 'n',
'ŕ' => 'r',
'ř' => 'r',
'š' => 's',
'ş' => 's',
'Ş' => 's',
'ť' => 't',
'ý' => 'y',
'ž' => 'z',
'а' => 'a',
'б' => 'b',
'в' => 'v',
'г' => 'g',
'д' => 'd',
'е' => 'e',
'ё' => 'e',
'з' => 'z',
'и' => 'i',
'й' => 'i',
'к' => 'k',
'л' => 'l',
'м' => 'm',
'н' => 'n',
'о' => 'o',
'п' => 'p',
'р' => 'r',
'с' => 's',
'т' => 't',
'у' => 'u',
'ф' => 'f',
'ы' => 'y',
'э' => 'e',
'ę' => 'e',
'ą' => 'a',
'ś' => 's',
'ł' => 'l',
'ż' => 'z',
'ź' => 'z',
);
/**
* Whether or not the system has LanguageSupportPageNames module installed
*
* @var bool
*
*/
protected $hasLanguagePageNames = false;
public function init() {
parent::init();
$this->label = $this->_('Name'); // Field label for 'Name'
$this->icon = 'angle-double-right';
$this->set('editPage', null); // page being edited, when available
$this->set('parentPage', null); // parent of page being edited, when available
$this->set('languageSupportLabel', '');
$this->set('slashUrls', 1); // whether a trailing slash should be shown in the URL preview
// disable autocomplete for page name with custom attribute value
$this->attr('autocomplete', 'pw-page-name');
// optional checkbox associated with the input, for use with language support
$this->set('checkboxName', ''); // leave blank to disable
$this->set('checkboxLabel', '');
$this->set('checkboxValue', '');
$this->set('checkboxChecked', false);
$this->set('checkboxSuffix', '');
if($this->wire('config')->pageNameCharset === 'UTF8') {
// no need to indicate input limitations
$this->set('sanitizeMethod', 'pageNameUTF8');
$this->description = '';
} else {
$this->description = $this->_("Any combination of letters (a-z), numbers (0-9), dashes or underscores (no spaces)."); // Field description describing what characters are allowed
$this->set('sanitizeMethod', 'pageName');
}
$this->hasLanguagePageNames = $this->wire()->modules->isInstalled('LanguageSupportPageNames');
$this->removeClass('InputfieldNoBorder', 'wrapClass');
}
public function ___render() {
$config = $this->wire()->config;
$url = '';
$out = '';
$box = '';
$user = $this->wire()->user;
$languages = $this->wire()->languages;
$sanitizer = $this->wire()->sanitizer;
$editable = $this->attr('disabled') ? false : true;
$template = $this->editPage ? $this->editPage->template : null;
$noLang = $template && $template->noLang;
if($this->parentPage) {
if($noLang && $languages && !$user->language->isDefault()) {
// if noLang active for page edited by non-default user, ensure we use default language url
$languages->setDefault();
$url = $this->parentPage->path;
$languages->unsetDefault();
} else {
$url = $this->parentPage->path;
}
if($this->hasLanguagePageNames && $this->parentPage->id == $config->rootPageID) {
if($user->language->isDefault()) {
$parentName = $this->parentPage->name;
if(!trim($url, '/')) $url = ($parentName === Pages::defaultRootName ? "" : $parentName);
}
}
}
if($noLang) $languages = false;
if($editable && $languages && $this->hasLanguagePageNames && !$languages->editable($user->language)) $editable = false;
if($this->languageSupportLabel) {
if($this->checkboxName) {
$checked = $this->checkboxChecked ? " checked='checked'" : '';
$disabled = $editable ? '' : " disabled='disabled'";
$name = $sanitizer->entities($this->checkboxName);
$value = $sanitizer->entities($this->checkboxValue);
$label = $sanitizer->entities($this->checkboxLabel);
$adminTheme = $this->wire()->adminTheme;
$checkboxClass = $adminTheme ? $adminTheme->getClass('input-checkbox') : '';
$box =
"";
}
$label = $sanitizer->entities($this->languageSupportLabel);
if(!$editable) $label = "$label";
$id = $sanitizer->entities($this->attr('id'));
$out .= "
"; if($link) $p .= $link; $p .= rtrim($url, '/') . "/"; if($link) $p .= "
"; $p .= ""; $out .= $p; $disabled = $this->attr('disabled'); if(!$editable) $this->attr('disabled', 'disabled'); $out .= parent::___render(); if(!$editable && !$disabled) $this->removeAttr('disabled'); // restore previous state if($this->languageSupportLabel) $out .= $box . "