Make "Yoonique’s Zoo Element Anywhere" extension syntax work with text field!

In case you hadn't heard about it yet, the guys at Yoonique have a nice plugin called  Zoo Element Anywhere that lets you insert elements from ZOO items into content anywhere in Joomla.

While using this in one of the projects our services team works on, we discovered that this had some limitations which we needed to get around.

The name of the plugin suggests that this plugin "Zoo Element Anywhere" will as the name says, work everywhere. However, we found that  it doesn't work "everywhere"; to be more specific, inside text fields. The syntax of this plugin only works inside text-area field and not in simple text field.

Note: This Blog is targeted towards developers!

Output :

Find out what we did to make it work ! Hopefully the Yoonique guys will apply this as a patch and make it standard :)

How do we make it work?

Simple steps you need to follow

Pre-requirement : “Zoo” and "Yoonique Zoo Element Anywhere" extension should be installed

                                and enabled on your joomla site.        

To override the text element of zoo, follow the below mentioned steps:

  public function render($params = array())
        {
                $params   = $this->app->data->create($params);
                $jplugins = $this->config->get('jplugins');

                if (($text = $this->get('value', '')) && !empty($text))
                {
                        $result[] = $text;
                }

                $regex = '/{yoonique_item:\s*(\S*)\s*element:\s*(.*?)(?:\s*config:(.*?))?}/i';

                for ($i = 0; $i < count($result); $i++)
                {
                        if (preg_match($regex, $result[$i]))
                        {
                                $result[$i] = $this->app->zoo->triggerContentPlugins($result[$i], array('item_id' => $this->_item->id), 'com_zoo.element.textarea');
                        }
                }

                return $this->app->element->applySeparators($params->get('separated_by'), $result);
}

 

 

Output :

NOTE : This will work only when you render the text field (that have Yoonique syntax) inside template.

If you guy’s don’t want to override Zoo text field for any reason, we have another solution, which will be published shortly ;)