1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-12 17:54:44 +02:00
This commit is contained in:
Ryan Cramer
2022-04-27 08:38:46 -04:00
parent 6001475a3c
commit cde0f53ad6
2 changed files with 26 additions and 17 deletions

View File

@@ -1435,6 +1435,7 @@ class Field extends WireData implements Saveable, Exportable {
* *
*/ */
public function setTags($tagList, $reindex = true) { public function setTags($tagList, $reindex = true) {
$textTools = $this->wire()->sanitizer->getTextTools();
if($tagList === null || $tagList === '') { if($tagList === null || $tagList === '') {
$tagList = array(); $tagList = array();
} else if(!is_array($tagList)) { } else if(!is_array($tagList)) {
@@ -1444,7 +1445,7 @@ class Field extends WireData implements Saveable, Exportable {
$tags = array(); $tags = array();
foreach($tagList as $tag) { foreach($tagList as $tag) {
$tag = trim($tag); $tag = trim($tag);
if(strlen($tag)) $tags[strtolower($tag)] = $tag; if(strlen($tag)) $tags[$textTools->strtolower($tag)] = $tag;
} }
$tagList = $tags; $tagList = $tags;
} }
@@ -1465,8 +1466,9 @@ class Field extends WireData implements Saveable, Exportable {
* *
*/ */
public function addTag($tag) { public function addTag($tag) {
$textTools = $this->wire()->sanitizer->getTextTools();
$tagList = $this->getTags(); $tagList = $this->getTags();
$tagList[strtolower($tag)] = $tag; $tagList[$textTools->strtolower($tag)] = $tag;
$this->setTags($tagList, false); $this->setTags($tagList, false);
return $tagList; return $tagList;
} }
@@ -1480,8 +1482,9 @@ class Field extends WireData implements Saveable, Exportable {
* *
*/ */
public function hasTag($tag) { public function hasTag($tag) {
$textTools = $this->wire()->sanitizer->getTextTools();
$tagList = $this->getTags(); $tagList = $this->getTags();
return isset($tagList[strtolower(trim(ltrim($tag, '-')))]); return isset($tagList[$textTools->strtolower(trim(ltrim($tag, '-')))]);
} }
/** /**
@@ -1493,8 +1496,9 @@ class Field extends WireData implements Saveable, Exportable {
* *
*/ */
public function removeTag($tag) { public function removeTag($tag) {
$textTools = $this->wire()->sanitizer->getTextTools();
$tagList = $this->getTags(); $tagList = $this->getTags();
$tag = strtolower($tag); $tag = $textTools->strtolower($tag);
if(!isset($tagList[$tag])) return $tagList; if(!isset($tagList[$tag])) return $tagList;
unset($tagList[$tag]); unset($tagList[$tag]);
return $this->setTags($tagList, false); return $this->setTags($tagList, false);

View File

@@ -332,16 +332,19 @@ class ProcessField extends Process implements ConfigurableModule {
* *
*/ */
public function ___execute() { public function ___execute() {
if($this->wire('config')->ajax) return $this->renderListJSON();
if($this->wire()->config->ajax) return $this->renderListJSON();
/** @var Session $session */ $session = $this->wire()->session;
$session = $this->wire('session'); $modules = $this->wire()->modules;
$textTools = $this->wire()->sanitizer->getTextTools();
$out = $this->getListFilterForm()->render() . "\n<div id='ProcessFieldList'>\n"; $out = $this->getListFilterForm()->render() . "\n<div id='ProcessFieldList'>\n";
$fieldsByTag = array(); $fieldsByTag = array();
$untaggedLabel = $this->_('Untagged'); $untaggedLabel = $this->_('Untagged');
$hasFilters = $session->getFor($this, 'filterTemplate') || $session->getFor($this, 'filterFieldtype'); $hasFilters = $session->getFor($this, 'filterTemplate') || $session->getFor($this, 'filterFieldtype');
$showSystem = $session->getFor($this, 'filterShowSystem'); $showSystem = $session->getFor($this, 'filterShowSystem');
$collapsedTags = $this->wire('modules')->getConfig($this, 'collapsedTags'); $collapsedTags = $modules->getConfig($this, 'collapsedTags');
$caseTags = array(); // indexed by lowercase version of tag $caseTags = array(); // indexed by lowercase version of tag
if(!is_array($collapsedTags)) $collapsedTags = array(); if(!is_array($collapsedTags)) $collapsedTags = array();
$systemTag = $this->_x('System', 'tag'); // Tag applied to the group of built-in/system fields $systemTag = $this->_x('System', 'tag'); // Tag applied to the group of built-in/system fields
@@ -355,7 +358,7 @@ class ProcessField extends Process implements ConfigurableModule {
} }
} }
if(empty($tags)) { if(empty($tags)) {
$tag = strtolower($untaggedLabel); $tag = $textTools->strtolower($untaggedLabel);
if(!isset($fieldsByTag[$tag])) $fieldsByTag[$tag] = array(); if(!isset($fieldsByTag[$tag])) $fieldsByTag[$tag] = array();
$fieldsByTag[$tag][$field->name] = $field; $fieldsByTag[$tag][$field->name] = $field;
$caseTags[$tag] = $untaggedLabel; $caseTags[$tag] = $untaggedLabel;
@@ -377,7 +380,7 @@ class ProcessField extends Process implements ConfigurableModule {
foreach($fieldsByTag as $tag => $fields) { foreach($fieldsByTag as $tag => $fields) {
ksort($fields); ksort($fields);
/** @var InputfieldMarkup $f */ /** @var InputfieldMarkup $f */
$f = $this->modules->get('InputfieldMarkup'); $f = $modules->get('InputfieldMarkup');
$f->entityEncodeLabel = false; $f->entityEncodeLabel = false;
$f->label = $caseTags[$tag]; $f->label = $caseTags[$tag];
$f->icon = 'tags'; $f->icon = 'tags';
@@ -394,7 +397,7 @@ class ProcessField extends Process implements ConfigurableModule {
$out .= "\n</div><!--/#ProcessFieldList-->"; $out .= "\n</div><!--/#ProcessFieldList-->";
/** @var InputfieldButton $button */ /** @var InputfieldButton $button */
$button = $this->modules->get('InputfieldButton'); $button = $modules->get('InputfieldButton');
$button->id = 'add_field_button'; $button->id = 'add_field_button';
$button->href = "./add"; $button->href = "./add";
$button->value = $this->_x('Add New Field', 'list button'); $button->value = $this->_x('Add New Field', 'list button');
@@ -402,15 +405,14 @@ class ProcessField extends Process implements ConfigurableModule {
$button->showInHeader(); $button->showInHeader();
$out .= $button->render(); $out .= $button->render();
$button = $this->modules->get('InputfieldButton'); $button = $modules->get('InputfieldButton');
$button->id = 'tags_button'; $button->id = 'tags_button';
$button->href = './tags/'; $button->href = './tags/';
$button->icon = 'tags'; $button->icon = 'tags';
$button->value = $this->labels['manage-tags']; $button->value = $this->labels['manage-tags'];
//$button->setSecondary();
$out .= $button->render(); $out .= $button->render();
$button = $this->modules->get('InputfieldButton'); $button = $modules->get('InputfieldButton');
$button->id = 'import_button'; $button->id = 'import_button';
$button->href = "./import/"; $button->href = "./import/";
$button->value = $this->labels['import']; $button->value = $this->labels['import'];
@@ -418,7 +420,7 @@ class ProcessField extends Process implements ConfigurableModule {
$button->setSecondary(); $button->setSecondary();
$out .= $button->render(); $out .= $button->render();
$button = $this->modules->get('InputfieldButton'); $button = $modules->get('InputfieldButton');
$button->id = 'export_button'; $button->id = 'export_button';
$button->href = "./export/"; $button->href = "./export/";
$button->value = $this->labels['export']; $button->value = $this->labels['export'];
@@ -426,7 +428,7 @@ class ProcessField extends Process implements ConfigurableModule {
$button->setSecondary(); $button->setSecondary();
$out .= $button->render(); $out .= $button->render();
if($this->input->get('nosave')) { if($this->wire()->input->get('nosave')) {
$session->removeFor($this, 'filterTemplate'); $session->removeFor($this, 'filterTemplate');
$session->removeFor($this, 'filterFieldtype'); $session->removeFor($this, 'filterFieldtype');
$session->removeFor($this, 'filterShowSystem'); $session->removeFor($this, 'filterShowSystem');
@@ -518,6 +520,7 @@ class ProcessField extends Process implements ConfigurableModule {
// save tag // save tag
$tagFields = $sanitizer->names($input->post('tag_fields')); $tagFields = $sanitizer->names($input->post('tag_fields'));
if(!is_array($tagFields)) $tagFields = array();
$renameTag = $sanitizer->words($input->post->text('rename_tag'), array('separator' => '-')); $renameTag = $sanitizer->words($input->post->text('rename_tag'), array('separator' => '-'));
$isCollapsed = (int) $input->post('tag_collapsed'); $isCollapsed = (int) $input->post('tag_collapsed');
$removeTag = ''; $removeTag = '';
@@ -1893,8 +1896,10 @@ class ProcessField extends Process implements ConfigurableModule {
$form->attr('title', $this->_x('Advanced', 'tab')); $form->attr('title', $this->_x('Advanced', 'tab'));
$tags = array(); $tags = array();
$textTools = $this->wire()->sanitizer->getTextTools();
foreach($this->wire()->fields->getTags() as $tagKey => $tagValue) { foreach($this->wire()->fields->getTags() as $tagKey => $tagValue) {
$tags[strtolower($tagKey)] = $tagValue; $tagKey = $textTools->strtolower($tagKey);
$tags[$tagKey] = $tagValue;
} }
ksort($tags); ksort($tags);
/** @var InputfieldTextTags $field */ /** @var InputfieldTextTags $field */