Skip to content

Commit

Permalink
Merge pull request #66 from RonakParmar/custom-fields
Browse files Browse the repository at this point in the history
#14 fixed Joomla Coding Standards and added function dock blocks code
  • Loading branch information
wilsonge committed Apr 6, 2016
2 parents e4007f9 + 90eb44e commit 11c79e1
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 13 deletions.
76 changes: 73 additions & 3 deletions administrator/components/com_fields/controllers/field.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,34 @@
/**
* @package Joomla.Administrator
* @subpackage com_fields
*
*
* @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;

use Joomla\Registry\Registry;

/**
* The Field controller
*
* @package Joomla.Administrator
* @subpackage com_fields
* @since 3.6
*/
class FieldsControllerField extends JControllerForm
{

private $internalContext;

private $component;

/**
* Class constructor.
*
* @param array $config A named array of configuration variables.
*
* @since 1.6
*/
public function __construct ($config = array())
{
parent::__construct($config);
Expand All @@ -34,19 +47,40 @@ public function catchange ()
$data = $this->input->get($this->input->get('formcontrol', 'jform'), array(), 'array');

$parts = FieldsHelper::extract($this->input->getCmd('context'));

if ($parts)
{
$app->setUserState($parts[0] . '.edit.' . $parts[1] . '.data', $data);
}

$app->redirect(base64_decode($this->input->get->getBase64('return')));
$app->close();
}

/**
* Method override to check if you can add a new record.
*
* @param array $data An array of input data.
*
* @return boolean
*
* @since 1.6
*/
protected function allowAdd ($data = array())
{
return JFactory::getUser()->authorise('core.create', $this->component);
}

/**
* Method override to check if you can edit an existing record.
*
* @param array $data An array of input data.
* @param string $key The name of the key for the primary key.
*
* @return boolean
*
* @since 1.6
*/
protected function allowEdit ($data = array(), $key = 'parent_id')
{
$recordId = (int) isset($data[$key]) ? $data[$key] : 0;
Expand Down Expand Up @@ -95,6 +129,15 @@ protected function allowEdit ($data = array(), $key = 'parent_id')
return false;
}

/**
* Method to run batch operations.
*
* @param object $model The model.
*
* @return boolean True if successful, false otherwise and internal error is set.
*
* @since 1.6
*/
public function batch ($model = null)
{
JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
Expand All @@ -108,6 +151,16 @@ public function batch ($model = null)
return parent::batch($model);
}

/**
* Gets the URL arguments to append to an item redirect.
*
* @param integer $recordId The primary key id for the item.
* @param string $urlVar The name of the URL variable for the id.
*
* @return string The arguments to append to the redirect URL.
*
* @since 1.6
*/
protected function getRedirectToItemAppend ($recordId = null, $urlVar = 'id')
{
$append = parent::getRedirectToItemAppend($recordId);
Expand All @@ -116,6 +169,13 @@ protected function getRedirectToItemAppend ($recordId = null, $urlVar = 'id')
return $append;
}

/**
* Gets the URL arguments to append to a list redirect.
*
* @return string The arguments to append to the redirect URL.
*
* @since 1.6
*/
protected function getRedirectToListAppend ()
{
$append = parent::getRedirectToListAppend();
Expand All @@ -124,13 +184,23 @@ protected function getRedirectToListAppend ()
return $append;
}

/**
* Function that allows child controller access to model data after the data has been saved.
*
* @param JModelLegacy $model The data model object.
* @param array $validData The validated data.
*
* @return void
*
* @since 3.1
*/
protected function postSaveHook (JModelLegacy $model, $validData = array())
{
$item = $model->getItem();

if (isset($item->params) && is_array($item->params))
{
$registry = new Registry();
$registry = new Registry;
$registry->loadArray($item->params);
$item->params = (string) $registry;
}
Expand Down
43 changes: 33 additions & 10 deletions administrator/components/com_fields/controllers/fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,62 @@
/**
* @package Joomla.Administrator
* @subpackage com_fields
*
*
* @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;

/**
* Fields list controller class.
*
* @since 3.6
*/
class FieldsControllerFields extends JControllerAdmin
{

/**
* Removes an item
*
* @return void
*
* @since 12.2
*/
public function delete ()
{
$return = parent::delete();

$this->setRedirect(
JRoute::_(
'index.php?option=' . $this->option . '&view=' . $this->view_list . '&context=' .
$this->input->getCmd('context', 'com_content.article'), false));
$this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_list . '&context=' . $this->input->getCmd('context', 'com_content.article'), false));

return $return;
}

/**
* Method to publish a list of items
*
* @return void
*
* @since 12.2
*/
public function publish ()
{
$return = parent::publish();

$this->setRedirect(
JRoute::_(
'index.php?option=' . $this->option . '&view=' . $this->view_list . '&context=' .
$this->input->getCmd('context', 'com_content.article'), false));
$this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_list . '&context=' . $this->input->getCmd('context', 'com_content.article'), false));

return $return;
}

/**
* Proxy for getModel.
*
* @param string $name The model name. Optional.
* @param string $prefix The class prefix. Optional.
* @param array $config The array of possible config values. Optional.
*
* @return JModel
*
* @since 1.6
*/
public function getModel ($name = 'Field', $prefix = 'FieldsModel', $config = array('ignore_request' => true))
{
$model = parent::getModel($name, $prefix, $config);
Expand Down

0 comments on commit 11c79e1

Please sign in to comment.