Skip to content

Commit 2bae882

Browse files
author
Tito Alvarez
authored
Merge pull request #915 from shandak/NK-1206
REDCORE-604 Error after Joomla update
2 parents 20f7785 + dbbcd77 commit 2bae882

File tree

1 file changed

+11
-162
lines changed
  • extensions/libraries/redcore/controller

1 file changed

+11
-162
lines changed

extensions/libraries/redcore/controller/form.php

Lines changed: 11 additions & 162 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
* @license GNU General Public License version 2 or later, see LICENSE.
88
*/
99

10+
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
11+
1012
defined('JPATH_REDCORE') or die;
1113

1214
JLoader::import('joomla.application.component.controllerform');
@@ -24,174 +26,21 @@ class RControllerForm extends JControllerForm
2426
/**
2527
* Constructor.
2628
*
27-
* @param array $config An optional associative array of configuration settings.
28-
* Recognized key values include 'name', 'default_task', 'model_path', and
29-
* 'view_path' (this list is not meant to be comprehensive).
29+
* @param array $config An optional associative array of configuration settings.
30+
* Recognized key values include 'name', 'default_task', 'model_path', and
31+
* 'view_path' (this list is not meant to be comprehensive).
32+
* @param MVCFactoryInterface $factory The factory.
3033
*
3134
* @throws Exception
3235
*/
33-
public function __construct($config = array())
36+
public function __construct($config = [], MVCFactoryInterface $factory = null)
3437
{
35-
/** JControllerLegacy */
36-
$this->methods = array();
37-
$this->message = null;
38-
$this->messageType = 'message';
39-
$this->paths = array();
40-
$this->redirect = null;
41-
$this->taskMap = array();
42-
43-
if (defined('JDEBUG') && JDEBUG)
44-
{
45-
JLog::addLogger(array('text_file' => 'jcontroller.log.php'), JLog::ALL, array('controller'));
46-
}
47-
48-
$this->input = JFactory::getApplication()->input;
49-
50-
// Determine the methods to exclude from the base class.
51-
$xMethods = get_class_methods('JControllerLegacy');
52-
53-
// Get the public methods in this class using reflection.
54-
$r = new ReflectionClass($this);
55-
$rMethods = $r->getMethods(ReflectionMethod::IS_PUBLIC);
56-
57-
foreach ($rMethods as $rMethod)
58-
{
59-
$mName = $rMethod->getName();
60-
61-
// Add default display method if not explicitly declared.
62-
if (!in_array($mName, $xMethods) || $mName == 'display')
63-
{
64-
$this->methods[] = strtolower($mName);
65-
66-
// Auto register the methods as tasks.
67-
$this->taskMap[strtolower($mName)] = $mName;
68-
}
69-
}
70-
71-
// Set the view name
72-
if (empty($this->name))
73-
{
74-
if (array_key_exists('name', $config))
75-
{
76-
$this->name = $config['name'];
77-
}
78-
else
79-
{
80-
$this->name = $this->getName();
81-
}
82-
}
83-
84-
// Set a base path for use by the controller
85-
if (array_key_exists('base_path', $config))
86-
{
87-
$this->basePath = $config['base_path'];
88-
}
89-
else
90-
{
91-
$this->basePath = JPATH_COMPONENT;
92-
}
38+
parent::__construct($config, $factory);
9339

94-
// If the default task is set, register it as such
95-
if (array_key_exists('default_task', $config))
96-
{
97-
$this->registerDefaultTask($config['default_task']);
98-
}
99-
else
100-
{
101-
$this->registerDefaultTask('display');
102-
}
103-
104-
// Set the models prefix
105-
if (empty($this->model_prefix))
106-
{
107-
if (array_key_exists('model_prefix', $config))
108-
{
109-
// User-defined prefix
110-
$this->model_prefix = $config['model_prefix'];
111-
}
112-
else
113-
{
114-
$this->model_prefix = ucfirst($this->name) . 'Model';
115-
}
116-
}
117-
118-
// Set the default model search path
119-
if (array_key_exists('model_path', $config))
120-
{
121-
// User-defined dirs
122-
$this->addModelPath($config['model_path'], $this->model_prefix);
123-
}
124-
else
125-
{
126-
$this->addModelPath($this->basePath . '/models', $this->model_prefix);
127-
}
128-
129-
// Set the default view search path
130-
if (array_key_exists('view_path', $config))
131-
{
132-
// User-defined dirs
133-
$this->setPath('view', $config['view_path']);
134-
}
135-
else
136-
{
137-
$this->setPath('view', $this->basePath . '/views');
138-
}
139-
140-
// Set the default view.
141-
if (array_key_exists('default_view', $config))
142-
{
143-
$this->default_view = $config['default_view'];
144-
}
145-
elseif (empty($this->default_view))
146-
{
147-
$this->default_view = $this->getName();
148-
}
149-
150-
/** JControllerForm */
151-
// Guess the option as com_NameOfController
152-
if (empty($this->option))
153-
{
154-
$this->option = 'com_' . strtolower($this->getName());
155-
}
156-
157-
// Guess the JText message prefix. Defaults to the option.
158-
if (empty($this->text_prefix))
159-
{
160-
$this->text_prefix = strtoupper($this->option);
161-
}
162-
163-
// Guess the context as the suffix, eg: OptionControllerContent.
164-
if (empty($this->context))
165-
{
166-
$r = null;
167-
168-
if (!preg_match('/(.*)Controller(.*)/i', get_class($this), $r))
169-
{
170-
throw new Exception(JText::_('JLIB_APPLICATION_ERROR_CONTROLLER_GET_NAME'), 500);
171-
}
172-
173-
$this->context = strtolower($r[2]);
174-
}
175-
176-
// Apply, Save & New, and Save As copy should be standard on forms.
177-
$this->registerTask('apply', 'save');
178-
$this->registerTask('save2new', 'save');
179-
$this->registerTask('save2copy', 'save');
180-
181-
/** Custom */
182-
// Guess the item view as the context.
183-
if (empty($this->view_item))
184-
{
185-
$this->view_item = $this->context;
186-
}
187-
188-
// Guess the list view as the plural of the item view.
189-
if (empty($this->view_list))
190-
{
191-
$this->view_list = RInflector::pluralize($this->view_item);
192-
}
40+
$this->view_list = RInflector::pluralize($this->view_item);
19341

194-
if (!property_exists($this, 'input') || empty($this->input))
42+
// J2.5 compatibility
43+
if (empty($this->input))
19544
{
19645
$this->input = JFactory::getApplication()->input;
19746
}

0 commit comments

Comments
 (0)