1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-09 08:17:12 +02:00

Make Fields::getTags() and Templates::getTags() hookable per @outflux3 processwire/processwire-issues#1369

This commit is contained in:
Ryan Cramer
2021-05-19 09:32:14 -04:00
parent dd4926a9a1
commit e6a79dbbdf
2 changed files with 12 additions and 7 deletions

View File

@@ -26,6 +26,7 @@
* @method void changedType(Saveable $item, Fieldtype $fromType, Fieldtype $toType) #pw-hooker
* @method void changeTypeReady(Saveable $item, Fieldtype $fromType, Fieldtype $toType) #pw-hooker
* @method bool|Field clone(Field $item, $name = '') Clone a field and return it or return false on fail.
* @method array getTags($getFieldNames = false) Get tags for all fields (3.0.179+) #pw-advanced
*
*/
@@ -601,7 +602,8 @@ class Fields extends WireSaveableItems {
if($exception) {
$this->error("Field type change failed. Database reports: $error");
$database->exec("DROP TABLE `$table2`"); // QA
if($exception) $this->trackException($exception, true);
$severe = $this->wire()->process != 'ProcessField';
if($exception) $this->trackException($exception, $severe);
return false;
}
@@ -926,13 +928,15 @@ class Fields extends WireSaveableItems {
* - If you specify "reset" for the `$getFields` argument it returns a blank array and resets
* internal tags cache.
*
* #pw-advanced
*
* @param bool|string $getFieldNames Specify true to return associative array where keys are tags and values are field names
* …or specify the string "reset" to force getTags() to reset its cache, forcing it to reload on the next call.
* @return array
* @since 3.0.106
* @return array Both keys and values are tags in return value
* @since 3.0.106 + made hookable in 3.0.179
*
*/
public function getTags($getFieldNames = false) {
public function ___getTags($getFieldNames = false) {
if($getFieldNames === 'reset') {
$this->tagList = null;

View File

@@ -17,6 +17,7 @@
* @method array getExportData(Template $template) Export Template data for external use. #pw-advanced
* @method array setImportData(Template $template, array $data) Given an array of Template export data, import it to the given Template. #pw-advanced
* @method void fileModified(Template $template) Hook called when a template detects that its file has been modified. #pw-hooker
* @method array getTags($getTemplateNames = false) Get tags for all templates (3.0.179+) #pw-advanced
*
*/
class Templates extends WireSaveableItems {
@@ -789,11 +790,11 @@ class Templates extends WireSaveableItems {
* Get all tags used by templates
*
* @param bool $getTemplateNames Get arrays of template names for each tag? (default=false)
* @return array
* @since 3.0.176
* @return array In return value both key and value are the tag
* @since 3.0.176 + hookable in 3.0.179
*
*/
public function getTags($getTemplateNames = false) {
public function ___getTags($getTemplateNames = false) {
$tags = array();
foreach($this as $template) {
/** @var Template $template */