Skip to content

Commit

Permalink
Confirm Consent Plugin Rendering Issues (joomla#23153)
Browse files Browse the repository at this point in the history
* move to it own field

* move to it own field

* fix since

* $modalHTML

* init html and drone

* drone ...

* Move modal to field renderer (#40)

* Move modal to field renderer

* Fix var type

* Fix wrong variable

* __DEPLOY_VERSION__
  • Loading branch information
zero-24 authored and mbabker committed Nov 26, 2018
1 parent ed8eb5c commit 0ba637a
Show file tree
Hide file tree
Showing 2 changed files with 277 additions and 104 deletions.
108 changes: 4 additions & 104 deletions plugins/content/confirmconsent/confirmconsent.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,8 @@

defined('_JEXEC') or die;

use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Associations;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Uri\Uri;

/**
* The Joomla Core confirm consent plugin
Expand All @@ -32,14 +27,6 @@ class PlgContentConfirmConsent extends CMSPlugin
*/
protected $app;

/**
* The Database object.
*
* @var JDatabaseDriver
* @since 3.9.0
*/
protected $db;

/**
* Load the language file on instantiation.
*
Expand Down Expand Up @@ -78,37 +65,17 @@ public function onContentPrepareForm(JForm $form, $data)
}

// Get the consent box Text & the selected privacyarticle
$consentboxLabel = Text::_('PLG_CONTENT_CONFIRMCONSENT_CONSENTBOX_LABEL');
$consentboxText = (string) $this->params->get('consentbox_text', Text::_('PLG_CONTENT_CONFIRMCONSENT_FIELD_NOTE_DEFAULT'));
$privacyArticle = $this->params->get('privacy_article', false);

// When we have a article let's add the modal and make the title clickable
if ($privacyArticle)
{
$modalName = 'privacyArticle';
$modalParams['title'] = $consentboxLabel;
$modalParams['url'] = $this->getAssignedArticleUrl($privacyArticle);
$modalParams['height'] = 800;
$modalParams['width'] = "100%";
echo HTMLHelper::_('bootstrap.renderModal', 'modal-' . $modalName, $modalParams);

$attribs['data-toggle'] = 'modal';

$consentboxLabel = HTMLHelper::_(
'link',
'#modal-' . $modalName,
$consentboxLabel,
$attribs
);
}

$form->load('
<form>
<fieldset name="default">
<fieldset name="default" addfieldpath="/plugins/content/confirmconsent/fields">
<field
name="consentbox"
type="checkboxes"
label="' . htmlspecialchars($consentboxLabel, ENT_COMPAT, 'UTF-8') . '"
type="consentbox"
articleid="' . $privacyArticle . '"
label="PLG_CONTENT_CONFIRMCONSENT_CONSENTBOX_LABEL"
required="true"
>
<option value="0">' . htmlspecialchars($consentboxText, ENT_COMPAT, 'UTF-8') . '</option>
Expand All @@ -119,71 +86,4 @@ public function onContentPrepareForm(JForm $form, $data)

return true;
}

/**
* Return the url of the assigned article based on the current user language
*
* @param integer $articleId The form to be altered.
*
* @return string Returns the a tag containing everything for the modal
*
* @since 3.9.0
*/
private function getAssignedArticleUrl($articleId)
{
// Get the info from the article
$query = $this->db->getQuery(true)
->select($this->db->quoteName(array('id', 'catid', 'language')))
->from($this->db->quoteName('#__content'))
->where($this->db->quoteName('id') . ' = ' . (int) $articleId);
$this->db->setQuery($query);

try
{
$article = $this->db->loadObject();
}
catch (JDatabaseExceptionExecuting $e)
{
// Something at the database layer went wrong
return Route::_(
'index.php?option=com_content&view=article&id='
. $articleId . '&tmpl=component'
);
}

// Register ContentHelperRoute
JLoader::register('ContentHelperRoute', JPATH_BASE . '/components/com_content/helpers/route.php');

if (!Associations::isEnabled())
{
return Route::_(
ContentHelperRoute::getArticleRoute(
$article->id,
$article->catid,
$article->language
) . '&tmpl=component'
);
}

$associatedArticles = Associations::getAssociations('com_content', '#__content', 'com_content.item', $article->id);
$currentLang = Factory::getLanguage()->getTag();

if (isset($associatedArticles) && $currentLang !== $article->language && array_key_exists($currentLang, $associatedArticles))
{
return Route::_(
ContentHelperRoute::getArticleRoute(
$associatedArticles[$currentLang]->id,
$associatedArticles[$currentLang]->catid,
$associatedArticles[$currentLang]->language
) . '&tmpl=component'
);
}

// Association is enabled but this article is not associated
return Route::_(
'index.php?option=com_content&view=article&id='
. $article->id . '&catid=' . $article->catid
. '&tmpl=component&lang=' . $article->language
);
}
}
Loading

0 comments on commit 0ba637a

Please sign in to comment.