fix: [plugins:tags] Use correct namespace and variable name

pull/72/head
Sami Mokaddem 2021-10-01 15:13:18 +02:00
parent e93821685c
commit 85ee7c69a5
12 changed files with 34 additions and 33 deletions

View File

@ -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)) {

View File

@ -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])) {

View File

@ -1,6 +1,6 @@
<?php
namespace App\Model\Entity;
namespace Tags\Model\Entity;
use App\Model\Entity\AppModel;
@ -13,7 +13,7 @@ class Tag extends AppModel {
];
protected $_accessibleOnNew = [
'label' => true,
'name' => true,
'colour' => true,
];

View File

@ -1,8 +1,8 @@
<?php
namespace App\Model\Entity;
namespace Tags\Model\Entity;
use Cake\ORM\Entity;
use App\Model\Entity\AppModel;
class Tagged extends AppModel {

View File

@ -14,14 +14,14 @@ class TagsTable extends AppTable
public function initialize(array $config): void
{
$this->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;
}
}

View File

@ -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 = '<div class="tag-container-wrapper">';
$html .= '<div class="tag-container my-1 d-flex">';
@ -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;
}
}

View File

@ -1,11 +1,11 @@
<?php
echo $this->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',

View File

@ -34,8 +34,8 @@ echo $this->element('genericElements/IndexTable/index_table', [
'data_path' => 'id',
],
[
'name' => __('Label'),
'sort' => 'label',
'name' => __('Name'),
'sort' => 'name',
'element' => 'tag'
],
[

View File

@ -9,7 +9,7 @@ echo $this->element(
'path' => 'id'
],
[
'key' => __('Label'),
'key' => __('Name'),
'path' => '',
'type' => 'tag',
],

View File

@ -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')

View File

@ -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]);

View File

@ -376,7 +376,7 @@ class NavigationComponent extends Component
]
]),
'Tags' => $this->getDefaultCRUDConfig('Tags', [
'defaults' => ['depth-1' => ['textGetter' => 'label']]
'defaults' => ['depth-1' => ['textGetter' => 'name']]
]),
'LocalTools' => [
'routes' => [