Search

I think it's quite easy to build a custom data source to achieve this, but is there a core feature that returns all tags belonging to a tag list as data source? E. g. to build an archive that shows all available tags?

Nope. Perhaps there is a need for some kind of "About Me" style Data Source, where by you choose a field and the XML contains information about the field. In the case of a Tag List field, it might include a list of all the tags.

That would be primo.

Was this ever done?

Yes. The following should work, if you set the ID of your taglist:

<?php

    require_once(TOOLKIT . '/class.datasource.php');

    Class datasourcetags extends Datasource{

        var $dsParamROOTELEMENT = 'tags';
        var $dsFieldID = 'YOURTAGFIELDIDHERE';

        function __construct(&$parent, $env=NULL, $process_params=true){
            parent::__construct($parent, $env, $process_params);
            $this->_dependencies = array();
        }

        function about(){
            return array(
                     'name' => 'Tags',
                     'author' => array(
                            'name' => 'Nils Hörrmann',
                            'website' => 'http://nilshoerrmann.de',
                            'email' => 'post@nilshoerrmann.de'),
                     'version' => '1.0',
                     'release-date' => '2009-01-25');   
        }

        function grab(&$param_pool){
            $result = NULL;

            $sql = "SELECT DISTINCT `value` FROM `sym_entries_data_" . $this->dsFieldID . "` 
                    ORDER BY `value` ASC";
            $tags = $this->_Parent->Database->fetchCol('value', $sql);

            $result = new XMLElement($this->dsParamROOTELEMENT);
            foreach($tags as $tag){
                $result->appendChild(new XMLElement('item', 
                                        $tag, 
                                        array('handle' => Lang::createHandle($tag))));
            }

            return $result;
        }
    }

?>

Just copy this to a file called data.tags.php in /workspace/data-sources. If you like to use a different file name, don't forget to change the class name.

I have a very similar DS here with the addition that it returns the count of each tag occurrence, making it easy to build a tag cloud.

I've tried several times to integrate this into the Tag List field itself. My idea was that every DS it is attached to, a separate node inside the DS is created (e.g. <static-values>) into which the list is put. Once per DS, rather than once per entry.

The same could apply for other fields that can accept static values, names Select Boxes.

I failed in my attempt since at the Field level, when outputing its XML to a DS, it cannot access the XML of the parent DS. At this step I wanted to:

  • check to see whether a static-values node existed
  • check to see whether values for this field ID had been added
  • if not, add these static values

Ideally this functionality would be in some kind of about/meta node for each DS.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details