mirror of
https://github.com/processwire/processwire.git
synced 2025-08-11 09:14:58 +02:00
Add improved tags support for InputfieldFile and InputfieldImage. Now the UI is more tags oriented, and there are more config options for how the tags are input. This commit also adds a modified version of the Selectize js library to provide improved tag inputs.
This commit is contained in:
@@ -521,6 +521,59 @@ class Pagefiles extends WireArray implements PageFieldValueInterface {
|
||||
}
|
||||
return $item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of tags for all files in this Pagefiles array, or return files matching given tag(s)
|
||||
*
|
||||
* This method can either return a list of all tags available, or return all files
|
||||
* matching the given tag or tags (an alias of findTag method).
|
||||
*
|
||||
* ~~~~~
|
||||
* // Get string of all tags
|
||||
* $tagsString = $page->files->tags();
|
||||
*
|
||||
* // Get array of all tags
|
||||
* $tagsArray = $page->files->tags(true);
|
||||
*
|
||||
* // Find all files matching given tag
|
||||
* $pagefiles = $page->files->tags('foobar');
|
||||
* ~~~~~
|
||||
*
|
||||
* #pw-group-tags
|
||||
*
|
||||
* @param bool|string|array $value Specify one of the following:
|
||||
* - Omit to return all tags as a string.
|
||||
* - Boolean true if you want to return tags as an array (rather than string).
|
||||
* - Boolean false to return tags as an array, with lowercase enforced.
|
||||
* - String if you want to return files matching tags (See `Pagefiles::findTag()` method for usage)
|
||||
* - Array if you want to return files matching tags (See `Pagefiles::findTag()` method for usage)
|
||||
* @return string|array|Pagefiles Returns all tags as a string or an array, or Pagefiles matching given tag(s).
|
||||
* When a tags array is returned, it is an associative array where the key and value are both the tag (keys are always lowercase).
|
||||
* @see Pagefiles::findTag(), Pagefile::tags()
|
||||
*
|
||||
*/
|
||||
public function tags($value = null) {
|
||||
|
||||
if($value === null) {
|
||||
$returnString = true;
|
||||
$value = true;
|
||||
} else {
|
||||
$returnString = false;
|
||||
}
|
||||
|
||||
if(is_bool($value)) {
|
||||
// return array of tags
|
||||
$tags = array();
|
||||
foreach($this as $pagefile) {
|
||||
$tags = array_merge($tags, $pagefile->tags($value));
|
||||
}
|
||||
if($returnString) $tags = implode(' ', $tags);
|
||||
return $tags;
|
||||
}
|
||||
|
||||
// fallback to behavior of findTag
|
||||
return $this->findTag($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Track a change
|
||||
|
Reference in New Issue
Block a user