Documentation

Below you will find documentation on how to use our software. This contains easy-to-use steps by step guides with helpful screenshots on how to configure and get the best results.
 

Categories

Chapter 7: Adding Extra Fields [Modifying the ARKExtension class]

If you modified your component directly or used Joomla’s template override to add your editable region, please see the section below.                   

Firstly, you will need to change the contexts array to include the context for your extra field in the constructor method.

So, in our mycck.php file, in our ARKExtensionsMyCCK class we must change this line:

$this->inline_allowed_contexts = array('com_mycck.item','com_mycck.category');

To

$this->inline_allowed_contexts = array('com_mycck.item','com_mycck.category','com_mycck.textarea');

Next, we must update our class to check for that context.

So, if we are in that context, only, then we will add an editable region for the Textarea type.

if($this->context == 'com_mycck.textarea')
{	
	
	//Permisson Check
		
	//Set Asset number 
	$this->id = $this->item->item_id;
	$asset = 'com_mycck.item.'.$this->id;
	$createdBy = $this->item->created_by;
	
	$user = JFactory::getUser();		
	//can user edit item if not then bail
	if (!($user->authorise('core.edit', $asset) || ($user->authorise('core.edit.own', $asset) && $user->id == $createdBy)) )
	{
		return false;
	}		
	
				
	//need to override base class here for following check for categories
	/*filter article to see if it is being used to load a module if so skip it
	[widgetkit]
	{loadmodule}
	{loadposition}
	{module}
	{modulepos}
	{modulepos}
	{component}
	{article(s)}
	*/
		
	$text = $this->item->value[0];
	
	$test = preg_match('/\{(?:loadmodule|loadposition|module|modulepos|component|articles?)\s+(.*?)\}/i',$text);

	if(!$test)
		$test = preg_match('/\[widgetkit\s+(.*?)\]/i',$article->text);
	
	if($test)
	{	
		return false;
	}


	$this->type = 'textarea';

	$dispatcher = JEventDispatcher::getInstance();
	JPluginHelper::importPlugin('inline');
	$dispatcher->trigger('editable',array(&$this->item->text, array('id'=>$this->id.'_'.$this->item->field_id,'context'=>$this->dataContext,'itemtype'=>$this->type)));

	return true;

}
elseif(isset($this->item->introtext))
{
	return false;
} ... // rest of code as before

In the code, above, you can see we added logic to the prepare method, similar to what we did for the main type, but, you can see, we manually fire the inline event to add the editor region for our textarea type. We do this because, as you see, we also have to check if the text content contains any plugin tags for pulling through any modules, etc. If this is the case, we bail out at that point.

In our case, the textarea type field in our component fires off only the onContentPrepare event, and not onContentAfterDisplay. So, we are not able to rely on the base class checking this for us because we are too early in the process of rendering our textarea type.

If it is the case that your component fires off the onContentAfterDisplay for your extra field type, then you can do something similar to the following in the display method:

if($this->context == 'com_mycck.textarea')
{	
	
	//Permisson Check
		
	//Set Asset number 
	$this->id = $this->item->item_id.'_'.$this->item->field_id; //set the id 
	$asset = 'com_mycck.item.'.$this->item->item_id;
	$createdBy = $this->item->created_by;
	
	$user = JFactory::getUser();		
	//can user edit item if not then bail
	if (!($user->authorise('core.edit', $asset) || ($user->authorise('core.edit.own', $asset) && $user->id == $createdBy)) )
	{
		return false;
	}		
}
else
{
	... // if we get here then we assume we are the main item type
}
return parent::prepare();

One thing to pay special attention is that, here, we concatenate the ID of the field type and the item type. This is done because we need both references for later as the value for the extra field is stored in a link table, more about that later.

WebxSolution Ltd is not affiliated with or endorsed by the Joomla! Project or Open Source Matters. The Joomla! name and logo is used under a limited license granted by Open Source Matters the trademark holder in the United States and other countries.

Copyright © 2009 - 2016 WebxSolution Ltd
Powered by JoomlaWired