The tagging component

Tag list Tag list

A very important component of Sulu is its tagging functionality. Tags will be extensively used in our smart content feature, which will be implemented soon. We decided to develop this in dedicated tag bundle, because otherwise it would be coupled too closely to our content management section, and we thought it could be useful to use tags in other parts of Sulu or even in other projects, as well.

So we implemented a simple list, in which you can directly edit the tags. It’s very easy to change the name of the tag, since IDs of the tags are saved along with the objects they are attached to. A new tag can also be easily added using this list, as it does not have any side effect on existing data.

Redesign Redesign

The two remaining important functionalities, deleting and merging, are affected by another critical decision: The TagBundle manages all the tags available in a RDBMS, but it’s the responsibility of the other bundles to store the assignments to a tag. This was necessary, because we don’t save all the data in the same database (we use a RDBMS and PHPCR) and the TagBundle doesn’t know the structure of the other bundles.

After this decision some of the complexity could be ignored in the TagBundle, and will be moved to other bundles using Symfony’s EventDispatcher. When a tag gets deleted, or multiple tags are summarized into one, the TagBundle will dispatch special events, which other bundles can listen to. As previously mentioned it is the responsibility of these bundles to react to these events appropriately, namely removing the tags from all of its persisted objects.

Another nice feature already implemented is the assignment of tags in the content management section. For this we have used the TagList component of our frontend framework Husky. While you are typing you will get some suggestions matching your current input, and it is also possible to assign a not existing tag, which then will be created automatically.

All in all I can say that I am happy with our TagBundle, because it uses some nice Symfony features to stay detached from other Sulu components. The next step is to make use of the tag assignments for our smart content feature. Stay tuned to hear more about this feature soon!