Components Anywhere

Passing extra get parameters to the article containing the component tag

6 months 2 weeks ago #78602

Peter Bengtsson's Avatar Peter Bengtsson

Hi!

Is there a way to pass the extra "get" parameters that is sent to the article containing the modules anywhere call?

Link to the article:
index.php?option=com_content&view=article&catid=2&id=27&tmpl=component&design_id=90

Article content:
{component index.php?option=com_ppproduct&view=designer&tmpl=component}

What I need is for the "design_id=90" to be passed to the component call, is this possible?

(I have it working with modules anywhere but I cant remember how I did that, or if it supports it out of box)

- Peter

6 months 2 weeks ago #78603

Peter van Westen's Avatar Peter van Westen Admin

You would have to use Sourcerer to grab the url data and output the {component} tag through PHP.

6 months 2 weeks ago #78604

Peter Bengtsson's Avatar Peter Bengtsson

Ok, thanks!
I will just work around it by storing the value in the session, just would have prefered it to be able to do this.

But how about adding a feature that supports this, could limit the "get" parameters to those actualy given in a component call but if they have no value replace then with the matching parameters from the origin call like:

Article content:
{component index.php?option=com_ppproduct&view=designer&tmpl=component&design_id}

Then theplugin checks if design_id has a value, if not check the get parameters for a match, if found add that value to the component call.

- Peter

6 months 2 weeks ago #78605

Peter van Westen's Avatar Peter van Westen Admin

{source}<?php
   $design_id = JFactory::getApplication()->input->getInt('design_id', 0);
   echo '{' . 'component index.php?option=com_ppproduct&view=designer&tmpl=component&design_id=' . $design_id . '}';
?>{/source}

6 months 2 weeks ago #78606

Peter Bengtsson's Avatar Peter Bengtsson

I modded the plugin insted, but I probly put the code at the wrong place! ;D

In Plugin.php

	public static function passGetParameters( $text )
	{
		$url = preg_match( "/{component (.*)}$/", $text, $matches );
		$parts = parse_url( $matches[1] );
		parse_str($parts['query'], $query);

		$jinput = JFactory::getApplication()->input;
		foreach( $query as $key => &$option )
		{
			$key = str_replace( 'amp;', '', $key );
			
			switch( $key )
			{
				case "option" :
				case "view" :
				case "tmpl" :
					continue;
				default :
					{
						$value = $jinput->get($key, $option);

						$text = preg_replace("/{$key}[^\&^(}&)]*/", "{$key}={$value}", $text);
					}
			}
			
		}
		
		return $text;
	}

	public function onContentPrepare($context, &$article, &$params)
	{
		
		$article->text = Plugin::passGetParameters( $article->text );
		$article->introtext = Plugin::passGetParameters( $article->introtext );
		
		...

6 months 2 weeks ago #78607

Peter van Westen's Avatar Peter van Westen Admin

Hack the plugin at own risk. You're on your own with that.
Also, it prevents you from updating.

6 months 2 weeks ago #78609

Peter Bengtsson's Avatar Peter Bengtsson

Ofcorse I know that, althought this change is very non-intrusive and should not cause any issues at all and be compitable with any further updates.

Is there anywhere to submit patches etc?

6 months 2 weeks ago #78611

Peter van Westen's Avatar Peter van Westen Admin

This is not something I will be implementing any time soon.