# CMS tutorial beforeSave with tag\_string

**URL:** <https://discourse.cakephp.org/t/cms-tutorial-beforesave-with-tag-string/7051>\
**Category:** Need Help\
**Created:** [January 2, 2020, 3:51pm UTC](https://discourse.cakephp.org/t/cms-tutorial-beforesave-with-tag-string/7051 "2020-01-02T15:51:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Barnamax](https://avatars.discourse-cdn.com/v4/letter/b/67e7ee/32.png) [@Barnamax](https://discourse.cakephp.org/u/Barnamax)\
**Post date:** [January 2, 2020, 3:51pm UTC](https://discourse.cakephp.org/t/cms-tutorial-beforesave-with-tag-string/7051/1 "2020-01-02T15:51:56Z")

</div>

Hi,  
I’m finally moving from cakePhp2 to Cakephp4

So I’ve decided to follow the CMS tutorial, and when adding the virtual field tag\_string, there is something I don"t understand. ([https://book.cakephp.org/4/fr/tutorials-and-examples/cms/tags-and-users.html](https://book.cakephp.org/4/fr/tutorials-and-examples/cms/tags-and-users.html))

In the beforeFilter function I’ve debug the $entity.  
In this entity I can see the field ‘tag\_string’ with the updated value (coming from the form), and if I try to debug $entity-\>tag\_string, I can see the ‘old’ version of it, not the dirty version.

It seems it’s due to the protected function \_getTagString that detect $this-\>\_properties[‘tag\_string’] as null.

So what am I missing?

I thought this function was really usefull, but I can’t seem to make it work.  
I’ve checked on the Bookmark tuto as well, and it’s exactly the same code.

Thanks if someone comes by and help me

**edit : I’ve tried changing the function \_getTagString() to \_getTagString($tag\_string), and this way I can access the $tag\_string (updated version) and it seems to be working.**  
**Hope it can help someone else.**

regards  
Max

---

<div class="post-metadata">

**Author:** ![d10566040](https://avatars.discourse-cdn.com/v4/letter/d/7993a0/32.png) [@d10566040](https://discourse.cakephp.org/u/d10566040)\
**Post date:** [January 5, 2020, 10:44am UTC](https://discourse.cakephp.org/t/cms-tutorial-beforesave-with-tag-string/7051/2 "2020-01-05T10:44:24Z")

</div>

You are right, the full correct function is:

```
	protected function _getTagString($tag_string)
	{
			if (isset($tag_string)) {
					return $tag_string;
			}
			if (empty($this->tags)) {
					return '';
			}
			$tags = new Collection($this->tags);
			$str = $tags->reduce(function ($string, $tag) {
					return $string . $tag->title . ', ';
			}, '');
			return trim($str, ', ');
	}

```

They should update CMS tutorial, case all this research maybe is not in begginers hand…
