Skip to content

Commit

Permalink
Guess the factory
Browse files Browse the repository at this point in the history
  • Loading branch information
laoneo committed May 22, 2017
1 parent f1d63f3 commit 348cbdb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
17 changes: 16 additions & 1 deletion libraries/src/CMS/Model/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@

defined('JPATH_PLATFORM') or die;

use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Mvc\Factory\LegacyFactory;
use Joomla\CMS\Mvc\Factory\MvcFactory;
use Joomla\CMS\Mvc\Factory\MvcFactoryInterface;
use Joomla\CMS\Table\Table;
use Joomla\Utilities\ArrayHelper;
Expand Down Expand Up @@ -240,7 +242,7 @@ public function __construct($config = array(), MvcFactoryInterface $factory = nu
throw new \Exception(\JText::_('JLIB_APPLICATION_ERROR_MODEL_GET_NAME'), 500);
}

$this->option = \JComponentHelper::getComponentName($this, $r[1]);
$this->option = ComponentHelper::getComponentName($this, $r[1]);
}

// Set the view name
Expand Down Expand Up @@ -306,6 +308,19 @@ public function __construct($config = array(), MvcFactoryInterface $factory = nu
$this->event_clean_cache = 'onContentCleanCache';
}

if (!$factory)
{
$reflect = new \ReflectionClass($this);
if ($reflect->getNamespaceName())
{
// Guess the root namespace
$ns = explode('\\', $reflect->getNamespaceName());
$ns = implode('\\', array_slice($ns, 0, 3));

$factory = new MvcFactory($ns, \JFactory::getApplication());
}
}

$this->factory = $factory ? : new LegacyFactory;
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/system/fields/fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function onContentAfterSave($context, $item, $isNew, $data = array())
$fieldsData = !empty($data['com_fields']) ? $data['com_fields'] : array();

// Loading the model
$model = JModelLegacy::getInstance('Field', 'FieldsModel', array('ignore_request' => true));
$model = new \Joomla\Component\Fields\Administrator\Model\Field(array('ignore_request' => true));

// Loop over the fields
foreach ($fields as $field)
Expand Down

0 comments on commit 348cbdb

Please sign in to comment.