2 minutes reading time (358 words)

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

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

  • Override the text element of Zoo Component.

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:

  • Copy the "text" folder from "/media/zoo/elements" and paste it in "/media/zoo/applications/(your application; for eg : blog)/elements".
  • Now, open "media/zoo/applications/(your application; for eg : blog)/elements/text/text.php" file.
  • In this file, paste the below function after _renderSubmission() function
  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);
}

 

 

  • Save and close the file.
  • Now you would be able to use Yoonique’s short-code syntax in text field also.

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

 

 

4
Mutual Friends v2.2 released for both CB & JomSoci...
How to provide live updates for extensions in Joom...