From 85ee7c69a5d951225eee80acc688b9dc5d5da217 Mon Sep 17 00:00:00 2001 From: Sami Mokaddem Date: Fri, 1 Oct 2021 15:13:18 +0200 Subject: [PATCH] fix: [plugins:tags] Use correct namespace and variable name --- plugins/Tags/src/Controller/TagsController.php | 4 ++-- plugins/Tags/src/Model/Behavior/TagBehavior.php | 16 ++++++++-------- plugins/Tags/src/Model/Entity/Tag.php | 4 ++-- plugins/Tags/src/Model/Entity/Tagged.php | 4 ++-- plugins/Tags/src/Model/Table/TagsTable.php | 4 ++-- plugins/Tags/src/View/Helper/TagHelper.php | 15 ++++++++------- plugins/Tags/templates/Tags/add.php | 6 +++--- plugins/Tags/templates/Tags/index.php | 4 ++-- plugins/Tags/templates/Tags/view.php | 2 +- plugins/Tags/webroot/js/tagging.js | 2 +- src/Controller/Component/CRUDComponent.php | 4 ++-- src/Controller/Component/NavigationComponent.php | 2 +- 12 files changed, 34 insertions(+), 33 deletions(-) diff --git a/plugins/Tags/src/Controller/TagsController.php b/plugins/Tags/src/Controller/TagsController.php index ab75bc9..6b018f4 100644 --- a/plugins/Tags/src/Controller/TagsController.php +++ b/plugins/Tags/src/Controller/TagsController.php @@ -18,8 +18,8 @@ class TagsController extends AppController public function index() { $this->CRUD->index([ - 'filters' => ['label', 'colour'], - 'quickFilters' => [['label' => true], 'colour'] + 'filters' => ['name', 'colour'], + 'quickFilters' => [['name' => true], 'colour'] ]); $responsePayload = $this->CRUD->getResponsePayload(); if (!empty($responsePayload)) { diff --git a/plugins/Tags/src/Model/Behavior/TagBehavior.php b/plugins/Tags/src/Model/Behavior/TagBehavior.php index 3db1b67..b27ded9 100644 --- a/plugins/Tags/src/Model/Behavior/TagBehavior.php +++ b/plugins/Tags/src/Model/Behavior/TagBehavior.php @@ -10,7 +10,7 @@ use Cake\ORM\Table; class TagBehavior extends Behavior { protected $_defaultConfig = [ - 'finderField' => 'label', + 'finderField' => 'name', 'tagsAssoc' => [ 'className' => 'Tags.Tags', 'joinTable' => 'tags_tagged', @@ -132,13 +132,13 @@ class TagBehavior extends Behavior continue; } - $existingTag = $this->getExistingTag($tag->label); - if (!$existing) { + $existingTag = $this->getExistingTag($tag->name); + if (!$existingTag) { continue; } $joinData = $tag->_joinData; - $tag = $existing; + $tag = $existingTag; $tag->_joinData = $joinData; $entity->tags[$k] = $tag; } @@ -180,7 +180,7 @@ class TagBehavior extends Behavior $result[] = array_merge( $common, [ - 'label' => $tagIdentifier, + 'name' => $tagIdentifier, ] ); } @@ -191,7 +191,7 @@ class TagBehavior extends Behavior protected function getTagIdentifier($tag) { if (is_object($tag)) { - return $tag->label; + return $tag->name; } else { return trim($tag); } @@ -201,7 +201,7 @@ class TagBehavior extends Behavior { $tagsTable = $this->_table->Tags->getTarget(); $query = $tagsTable->find()->where([ - 'Tags.label' => $tagName + 'Tags.name' => $tagName ]) ->select('Tags.id'); return $query->first(); @@ -210,7 +210,7 @@ class TagBehavior extends Behavior public function findByTag(Query $query, array $options) { $finderField = $optionsKey = $this->getConfig('finderField'); if (!$finderField) { - $finderField = $optionsKey = 'label'; + $finderField = $optionsKey = 'name'; } if (!isset($options[$optionsKey])) { diff --git a/plugins/Tags/src/Model/Entity/Tag.php b/plugins/Tags/src/Model/Entity/Tag.php index 19802f0..d98514e 100644 --- a/plugins/Tags/src/Model/Entity/Tag.php +++ b/plugins/Tags/src/Model/Entity/Tag.php @@ -1,6 +1,6 @@ true, + 'name' => true, 'colour' => true, ]; diff --git a/plugins/Tags/src/Model/Entity/Tagged.php b/plugins/Tags/src/Model/Entity/Tagged.php index eac3b44..38c5b26 100644 --- a/plugins/Tags/src/Model/Entity/Tagged.php +++ b/plugins/Tags/src/Model/Entity/Tagged.php @@ -1,8 +1,8 @@ setTable('tags_tags'); - $this->setDisplayField('label'); // Change to name? + $this->setDisplayField('name'); // Change to name? $this->addBehavior('Timestamp'); } public function validationDefault(Validator $validator): Validator { $validator - ->notBlank('label'); + ->notBlank('name'); return $validator; } } diff --git a/plugins/Tags/src/View/Helper/TagHelper.php b/plugins/Tags/src/View/Helper/TagHelper.php index fba05eb..ab9122e 100644 --- a/plugins/Tags/src/View/Helper/TagHelper.php +++ b/plugins/Tags/src/View/Helper/TagHelper.php @@ -27,8 +27,8 @@ class TagHelper extends Helper $field = 'tag_list'; $values = !empty($options['allTags']) ? array_map(function($tag) { return [ - 'text' => h($tag['label']), - 'value' => h($tag['label']), + 'text' => h($tag['name']), + 'value' => h($tag['name']), 'data-colour' => h($tag['colour']), 'data-text-colour' => h($tag['text_colour']), ]; @@ -70,8 +70,9 @@ class TagHelper extends Helper return $html; } - public function tags(array $tags = [], array $options = []) + public function tags($tags = [], array $options = []) { + $tags = is_null($tags) ? [] : $tags; $this->_config = array_merge($this->defaultConfig, $options); $html = '
'; $html .= '
'; @@ -81,7 +82,7 @@ class TagHelper extends Helper $html .= $this->tag($tag); } else { $html .= $this->tag([ - 'label' => $tag + 'name' => $tag ]); } } @@ -117,7 +118,7 @@ class TagHelper extends Helper 'action' => 'untag', $this->getView()->get('entity')['id'] ]), - h($tag['label']) + h($tag['name']) ), ], ]); @@ -132,9 +133,9 @@ class TagHelper extends Helper 'mx-1', 'align-middle', ], - 'title' => h($tag['label']), + 'title' => h($tag['name']), 'style' => sprintf('color:%s; background-color:%s', $textColour, h($tag['colour'])), - ], h($tag['label']) . $deleteButton); + ], h($tag['name']) . $deleteButton); return $html; } } diff --git a/plugins/Tags/templates/Tags/add.php b/plugins/Tags/templates/Tags/add.php index 412dc1c..89eb5e9 100644 --- a/plugins/Tags/templates/Tags/add.php +++ b/plugins/Tags/templates/Tags/add.php @@ -1,11 +1,11 @@ element('genericElements/Form/genericForm', array( 'data' => array( - 'description' => __('Individuals are natural persons. They are meant to describe the basic information about an individual that may or may not be a user of this community. Users in genral require an individual object to identify the person behind them - however, no user account is required to store information about an individual. Individuals can have affiliations to organisations and broods as well as cryptographic keys, using which their messages can be verified and which can be used to securely contact them.'), - 'model' => 'Organisations', + 'description' => __('Tags can be attached to entity to quickly classify them, allowing further filtering and searches.'), + 'model' => 'Tags', 'fields' => array( array( - 'field' => 'label' + 'field' => 'name' ), array( 'field' => 'colour', diff --git a/plugins/Tags/templates/Tags/index.php b/plugins/Tags/templates/Tags/index.php index a826fb1..4f1a041 100644 --- a/plugins/Tags/templates/Tags/index.php +++ b/plugins/Tags/templates/Tags/index.php @@ -34,8 +34,8 @@ echo $this->element('genericElements/IndexTable/index_table', [ 'data_path' => 'id', ], [ - 'name' => __('Label'), - 'sort' => 'label', + 'name' => __('Name'), + 'sort' => 'name', 'element' => 'tag' ], [ diff --git a/plugins/Tags/templates/Tags/view.php b/plugins/Tags/templates/Tags/view.php index 0886fc9..a037895 100644 --- a/plugins/Tags/templates/Tags/view.php +++ b/plugins/Tags/templates/Tags/view.php @@ -9,7 +9,7 @@ echo $this->element( 'path' => 'id' ], [ - 'key' => __('Label'), + 'key' => __('Name'), 'path' => '', 'type' => 'tag', ], diff --git a/plugins/Tags/webroot/js/tagging.js b/plugins/Tags/webroot/js/tagging.js index b2565e1..606ad21 100644 --- a/plugins/Tags/webroot/js/tagging.js +++ b/plugins/Tags/webroot/js/tagging.js @@ -101,7 +101,7 @@ function initSelect2Picker($select) { function templateTag(state, $select) { if (!state.id) { - return state.label; + return state.name; } if (state.colour === undefined) { state.colour = $(state.element).data('colour') diff --git a/src/Controller/Component/CRUDComponent.php b/src/Controller/Component/CRUDComponent.php index 6a5244a..ac30776 100644 --- a/src/Controller/Component/CRUDComponent.php +++ b/src/Controller/Component/CRUDComponent.php @@ -512,7 +512,7 @@ class CRUDComponent extends Component $tagsToRemove = json_decode($input['tag_list']); // patching will mirror tag in the DB, however, we only want to remove tags $input['tags'] = array_filter($entity->tags, function ($existingTag) use ($tagsToRemove) { - return !in_array($existingTag->label, $tagsToRemove); + return !in_array($existingTag->name, $tagsToRemove); }); $patchEntityParams = [ 'fields' => ['tags'], @@ -742,7 +742,7 @@ class CRUDComponent extends Component { $modelAlias = $this->Table->getAlias(); $subQuery = $this->Table->find('tagged', [ - 'label' => $tags, + 'name' => $tags, 'forceAnd' => true ])->select($modelAlias . '.id'); return $query->where([$modelAlias . '.id IN' => $subQuery]); diff --git a/src/Controller/Component/NavigationComponent.php b/src/Controller/Component/NavigationComponent.php index 58e0b6b..a183b7e 100644 --- a/src/Controller/Component/NavigationComponent.php +++ b/src/Controller/Component/NavigationComponent.php @@ -376,7 +376,7 @@ class NavigationComponent extends Component ] ]), 'Tags' => $this->getDefaultCRUDConfig('Tags', [ - 'defaults' => ['depth-1' => ['textGetter' => 'label']] + 'defaults' => ['depth-1' => ['textGetter' => 'name']] ]), 'LocalTools' => [ 'routes' => [