?
avatar infograf768
infograf768
14 Sep 2020

Steps to reproduce the issue

Create a contact.
Create a single Contact menu item to display this contact.

Modify the Contact Publishing parameters.
For example:
Set it to Unpublished
Or, set it to Published and modify publish up or down so as to not display the contact when the menu item is clicked to therefore obtain a 404.

Expected result

404 Contact not found

Actual result

Argument 1 passed to Joomla\Registry\Registry::merge() must be an instance of Joomla\Registry\Registry, null given, called in /Applications/MAMP/htdocs/newfolder/joomla40/components/com_contact/src/Model/ContactModel.php on line 132

Trying to solve the issue

Modifying ContactModel.php line 132 to use registry
From

$temp->merge($contact->params);
$contact->params = $temp;

to

$registry = new Registry($contact->params);
$temp->merge($registry);
$contact->params = $temp;

We now get
Argument 1 passed to Joomla\Registry\Registry::merge() must be an instance of Joomla\Registry\Registry, null given, called in /Applications/MAMP/htdocs/newfolder/joomla40/components/com_contact/src/View/Contact/HtmlView.php on line 147

Modifying Contact/HtmlView.php

Adding use Joomla\Registry\Registry;
Then change line 147 from

$temp->merge($item->params);
$item->params = $temp;

to

$registry = new Registry($item->params);
$temp->merge($registry);
$item->params = $temp;

Result:

500 Exception: Contact not found in /Applications/MAMP/htdocs/newfolder/joomla40/components/com_contact/src/Model/ContactModel.php:249 Stack trace: #0 /Applications/MAMP/htdocs/newfolder/joomla40/libraries/src/MVC/View/AbstractView.php(146): Joomla\Component\Contact\Site\Model\ContactModel->getItem() #1 /Applications/MAMP/htdocs/newfolder/joomla40/components/com_contact/src/View/Contact/HtmlView.php(118): Joomla\CMS\MVC\View\AbstractView->get('Item') #2 /Applications/MAMP/htdocs/newfolder/joomla40/libraries/src/MVC/Controller/BaseController.php(691): Joomla\Component\Contact\Site\View\Contact\HtmlView->display() #3 /Applications/MAMP/htdocs/newfolder/joomla40/components/com_contact/src/Controller/DisplayController.php(81): Joomla\CMS\MVC\Controller\BaseController->display(false, Array) #4 /Applications/MAMP/htdocs/newfolder/joomla40/libraries/src/MVC/Controller/BaseController.php(729): Joomla\Component\Contact\Site\Controller\DisplayController->display() #5 /Applications/MAMP/htdocs/newfolder/joomla40/libraries/src/Dispatcher/ComponentDispatcher.php(146): Joomla\CMS\MVC\Controller\BaseController->execute('display') #6 /Applications/MAMP/htdocs/newfolder/joomla40/components/com_contact/src/Dispatcher/Dispatcher.php(45): Joomla\CMS\Dispatcher\ComponentDispatcher->dispatch() #7 /Applications/MAMP/htdocs/newfolder/joomla40/libraries/src/Component/ComponentHelper.php(389): Joomla\Component\Contact\Site\Dispatcher\Dispatcher->dispatch() #8 /Applications/MAMP/htdocs/newfolder/joomla40/libraries/src/Application/SiteApplication.php(206): Joomla\CMS\Component\ComponentHelper::renderComponent('com_contact') #9 /Applications/MAMP/htdocs/newfolder/joomla40/libraries/src/Application/SiteApplication.php(245): Joomla\CMS\Application\SiteApplication->dispatch() #10 /Applications/MAMP/htdocs/newfolder/joomla40/libraries/src/Application/CMSApplication.php(231): Joomla\CMS\Application\SiteApplication->doExecute() #11 /Applications/MAMP/htdocs/newfolder/joomla40/includes/app.php(63): Joomla\CMS\Application\CMSApplication->execute() #12 /Applications/MAMP/htdocs/newfolder/joomla40/index.php(36): require_once('/Applications/M...') #13 {main} 

I.e. instead of getting a 404 from the ContactModel

if (empty($data))
{
	throw new \Exception(Text::_('COM_CONTACT_ERROR_CONTACT_NOT_FOUND'), 404);
}

we get the result from the HtmlView.php code

		// Check for errors.
		if (count($errors = $this->get('Errors')))
		{
			throw new GenericDataException(implode("\n", $errors), 500);
		}

Note:

  1. There may be other places where Registry should be used
  2. The same (or very similar) code for article uses the 404 from the ArticleModel. No registry error.
avatar infograf768 infograf768 - open - 14 Sep 2020
avatar joomla-cms-bot joomla-cms-bot - change - 14 Sep 2020
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - labeled - 14 Sep 2020
avatar Formatio-hippocampi
Formatio-hippocampi - comment - 14 Sep 2020

Issue confirmed for
image

avatar alikon
alikon - comment - 14 Sep 2020

change https://github.com/joomla/joomla-cms/blob/4.0-dev/components/com_contact/src/Model/ContactModel.php#L301-L305

with

			catch (\Exception $e)
			{
				if ($e->getCode() == 404)
				{
					// Need to go through the error handler to allow Redirect to work.
					throw new \Exception($e->getMessage(), 404);
				}
				else
				{
					$this->setError($e);
					$this->_item[$pk] = false;
				}
			}

should work as expected ..... can you confirm ?

avatar infograf768
infograf768 - comment - 14 Sep 2020

@alikon
This works great and I do not need to modify the Registry stuff.
I see the same code indeed for article model.
Can you make a PR?

avatar alikon
alikon - comment - 14 Sep 2020

sure i'll do shortly

avatar alikon alikon - change - 14 Sep 2020
Status New Closed
Closed_Date 0000-00-00 00:00:00 2020-09-14 18:07:02
Closed_By alikon
avatar alikon alikon - close - 14 Sep 2020
avatar alikon
alikon - comment - 14 Sep 2020

please test #30642

avatar infograf768
infograf768 - comment - 14 Sep 2020

@Formatio-hippocampi
please test pr. thanks

Add a Comment

Login with GitHub to post a comment