Skip to content

Commit

Permalink
CS
Browse files Browse the repository at this point in the history
  • Loading branch information
leofeyer committed Nov 4, 2021
1 parent 2dd6e97 commit 06ea58a
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 80 deletions.
Expand Up @@ -32,6 +32,10 @@ public function __construct(ContaoFramework $contaoFramework)

public function __invoke(DataContainer $dc): void
{
if (!$dc->id) {
return;
}

/** @var PageModel $pageModel */
$pageModel = $this->contaoFramework->getAdapter(PageModel::class);
$page = $pageModel->findWithDetails($dc->id);
Expand All @@ -41,8 +45,9 @@ public function __invoke(DataContainer $dc): void
}

PaletteManipulator::create()
->addField('canonicalKeepParams', 'serpPreview')
->addField('canonicalLink', 'serpPreview')
->addLegend('canonical_legend', 'meta_legend', PaletteManipulator::POSITION_AFTER, true)
->addField('canonicalLink', 'canonical_legend', PaletteManipulator::POSITION_APPEND)
->addField('canonicalKeepParams', 'canonical_legend', PaletteManipulator::POSITION_APPEND)
->applyToPalette('regular', 'tl_page')
;
}
Expand Down
2 changes: 1 addition & 1 deletion core-bundle/src/Resources/config/services.yml
Expand Up @@ -716,8 +716,8 @@ services:
- '@Contao\CoreBundle\Routing\ResponseContext\ResponseContextAccessor'
- '@event_dispatcher'
- '@contao.security.token_checker'
- '@contao.framework'
- '@Contao\CoreBundle\String\HtmlDecoder'
- '@contao.framework'
public: true

contao.search.indexer.default:
Expand Down
50 changes: 25 additions & 25 deletions core-bundle/src/Resources/contao/dca/tl_page.php
Expand Up @@ -180,8 +180,8 @@
'regular' => '{title_legend},title,alias,type;{meta_legend},pageTitle,robots,description,serpPreview;{protected_legend:hide},protected;{layout_legend:hide},includeLayout;{cache_legend:hide},includeCache;{chmod_legend:hide},includeChmod;{expert_legend:hide},cssClass,sitemap,hide,noSearch,guests,requireItem;{tabnav_legend:hide},tabindex,accesskey;{publish_legend},published,start,stop',
'forward' => '{title_legend},title,alias,type;{meta_legend},pageTitle,robots;{redirect_legend},jumpTo,redirect;{protected_legend:hide},protected;{layout_legend:hide},includeLayout;{cache_legend:hide},includeCache;{chmod_legend:hide},includeChmod;{expert_legend:hide},cssClass,sitemap,hide,guests;{tabnav_legend:hide},tabindex,accesskey;{publish_legend},published,start,stop',
'redirect' => '{title_legend},title,alias,type;{meta_legend},pageTitle,robots;{redirect_legend},redirect,url,target;{protected_legend:hide},protected;{layout_legend:hide},includeLayout;{cache_legend:hide},includeCache;{chmod_legend:hide},includeChmod;{expert_legend:hide},cssClass,sitemap,hide,guests;{tabnav_legend:hide},tabindex,accesskey;{publish_legend},published,start,stop',
'root' => '{title_legend},title,alias,type;{meta_legend},pageTitle,enableCanonical;{url_legend},dns,useSSL,urlPrefix,urlSuffix,validAliasCharacters,useFolderUrl;{language_legend},language,fallback,disableLanguageRedirect;{global_legend:hide},adminEmail,mailerTransport,dateFormat,timeFormat,datimFormat,staticFiles,staticPlugins;{protected_legend:hide},protected;{layout_legend},includeLayout;{twoFactor_legend:hide},enforceTwoFactor;{cache_legend:hide},includeCache;{chmod_legend:hide},includeChmod;{publish_legend},published,start,stop',
'rootfallback' => '{title_legend},title,alias,type;{meta_legend},pageTitle,enableCanonical;{url_legend},dns,useSSL,urlPrefix,urlSuffix,validAliasCharacters,useFolderUrl;{language_legend},language,fallback,disableLanguageRedirect;{website_legend:hide},favicon,robotsTxt;{global_legend:hide},adminEmail,mailerTransport,dateFormat,timeFormat,datimFormat,staticFiles,staticPlugins;{protected_legend:hide},protected;{layout_legend},includeLayout;{twoFactor_legend:hide},enforceTwoFactor;{cache_legend:hide},includeCache;{chmod_legend:hide},includeChmod;{publish_legend},published,start,stop',
'root' => '{title_legend},title,alias,type;{meta_legend},pageTitle;{url_legend},dns,useSSL,urlPrefix,urlSuffix,validAliasCharacters,useFolderUrl;{language_legend},language,fallback,disableLanguageRedirect;{global_legend:hide},mailerTransport,enableCanonical,adminEmail,dateFormat,timeFormat,datimFormat,staticFiles,staticPlugins;{protected_legend:hide},protected;{layout_legend},includeLayout;{twoFactor_legend:hide},enforceTwoFactor;{cache_legend:hide},includeCache;{chmod_legend:hide},includeChmod;{publish_legend},published,start,stop',
'rootfallback' => '{title_legend},title,alias,type;{meta_legend},pageTitle;{url_legend},dns,useSSL,urlPrefix,urlSuffix,validAliasCharacters,useFolderUrl;{language_legend},language,fallback,disableLanguageRedirect;{website_legend:hide},favicon,robotsTxt;{global_legend:hide},mailerTransport,enableCanonical,adminEmail,dateFormat,timeFormat,datimFormat,staticFiles,staticPlugins;{protected_legend:hide},protected;{layout_legend},includeLayout;{twoFactor_legend:hide},enforceTwoFactor;{cache_legend:hide},includeCache;{chmod_legend:hide},includeChmod;{publish_legend},published,start,stop',
'logout' => '{title_legend},title,alias,type;{forward_legend},jumpTo,redirectBack;{protected_legend:hide},protected;{chmod_legend:hide},includeChmod;{expert_legend:hide},cssClass,sitemap,hide;{tabnav_legend:hide},tabindex,accesskey;{publish_legend},published,start,stop',
'error_401' => '{title_legend},title,alias,type;{meta_legend},pageTitle,robots,description;{forward_legend},autoforward;{layout_legend:hide},includeLayout;{cache_legend:hide},includeCache;{chmod_legend:hide},includeChmod;{expert_legend:hide},cssClass;{publish_legend},published,start,stop',
'error_403' => '{title_legend},title,alias,type;{meta_legend},pageTitle,robots,description;{forward_legend},autoforward;{layout_legend:hide},includeLayout;{cache_legend:hide},includeCache;{chmod_legend:hide},includeChmod;{expert_legend:hide},cssClass;{publish_legend},published,start,stop',
Expand Down Expand Up @@ -253,14 +253,6 @@
'eval' => array('maxlength'=>255, 'tl_class'=>'w50'),
'sql' => "varchar(255) NOT NULL default ''"
),
'enableCanonical' => array
(
'exclude' => true,
'inputType' => 'checkbox',
'default' => true,
'eval' => array('tl_class'=>'w50 m12'),
'sql' => "char(1) NOT NULL default ''"
),
'language' => array
(
'exclude' => true,
Expand Down Expand Up @@ -307,21 +299,6 @@ static function ($value)
'eval' => array('url_callback'=>array('tl_page', 'getSerpUrl'), 'title_tag_callback'=>array('tl_page', 'getTitleTag'), 'titleFields'=>array('pageTitle', 'title')),
'sql' => null
),
'canonicalLink' => array
(
'exclude' => true,
'search' => true,
'inputType' => 'text',
'eval' => array('rgxp'=>'url', 'decodeEntities'=>true, 'maxlength'=>255, 'dcaPicker'=>true, 'tl_class'=>'w50'),
'sql' => "varchar(255) NOT NULL default ''"
),
'canonicalKeepParams' => array
(
'exclude' => true,
'inputType' => 'text',
'eval' => array('decodeEntities'=>true, 'maxlength'=>255, 'tl_class'=>'w50'),
'sql' => "varchar(255) NOT NULL default ''"
),
'redirect' => array
(
'exclude' => true,
Expand Down Expand Up @@ -446,6 +423,29 @@ static function ($value)
'eval' => array('tl_class'=>'w50', 'includeBlankOption'=>true),
'sql' => "varchar(255) NOT NULL default ''"
),
'enableCanonical' => array
(
'exclude' => true,
'inputType' => 'checkbox',
'default' => true,
'eval' => array('tl_class'=>'w50 m12'),
'sql' => "char(1) NOT NULL default ''"
),
'canonicalLink' => array
(
'exclude' => true,
'search' => true,
'inputType' => 'text',
'eval' => array('rgxp'=>'url', 'decodeEntities'=>true, 'maxlength'=>255, 'dcaPicker'=>true, 'tl_class'=>'w50'),
'sql' => "varchar(255) NOT NULL default ''"
),
'canonicalKeepParams' => array
(
'exclude' => true,
'inputType' => 'text',
'eval' => array('decodeEntities'=>true, 'maxlength'=>255, 'tl_class'=>'w50'),
'sql' => "varchar(255) NOT NULL default ''"
),
'adminEmail' => array
(
'exclude' => true,
Expand Down
39 changes: 21 additions & 18 deletions core-bundle/src/Resources/contao/languages/en/tl_page.xlf
Expand Up @@ -26,24 +26,6 @@
<trans-unit id="tl_page.pageTitle.1">
<source>Please enter the page title.</source>
</trans-unit>
<trans-unit id="tl_page.enableCanonical.0">
<source>Enable rel="canonical" support</source>
</trans-unit>
<trans-unit id="tl_page.enableCanonical.1">
<source>You can disable built-in rel="canonical" support and take control over it yourself.</source>
</trans-unit>
<trans-unit id="tl_page.canonicalLink.0">
<source>Manual rel="canonical" selection</source>
</trans-unit>
<trans-unit id="tl_page.canonicalLink.1">
<source>You can manually select the desired target page for rel="canonical" support.</source>
</trans-unit>
<trans-unit id="tl_page.canonicalKeepParams.0">
<source>Query parameters to keep for rel="canonical"</source>
</trans-unit>
<trans-unit id="tl_page.canonicalKeepParams.1">
<source>By default, Contao points to itself for rel="canonical". You may add a comma-separated list of query parameters which should be kept. Use "*" as a wildcard.</source>
</trans-unit>
<trans-unit id="tl_page.language.0">
<source>Language</source>
</trans-unit>
Expand Down Expand Up @@ -128,6 +110,24 @@
<trans-unit id="tl_page.mailerTransport.1">
<source>Here you can override the mailer transport used to send e-mails on this website.</source>
</trans-unit>
<trans-unit id="tl_page.enableCanonical.0">
<source>Enable rel="canonical"</source>
</trans-unit>
<trans-unit id="tl_page.enableCanonical.1">
<source>Add rel="canonical" tags to the website.</source>
</trans-unit>
<trans-unit id="tl_page.canonicalLink.0">
<source>Custom URL</source>
</trans-unit>
<trans-unit id="tl_page.canonicalLink.1">
<source>Here you can set a custom canonical URL.</source>
</trans-unit>
<trans-unit id="tl_page.canonicalKeepParams.0">
<source>Query parameters</source>
</trans-unit>
<trans-unit id="tl_page.canonicalKeepParams.1">
<source>By default, Contao strips the query paramters in the canonical URL. Here you can add a comma-separated list of query parameters to preserve. Use "*" as a wildcard.</source>
</trans-unit>
<trans-unit id="tl_page.adminEmail.0">
<source>E-mail address of the website administrator</source>
</trans-unit>
Expand Down Expand Up @@ -344,6 +344,9 @@
<trans-unit id="tl_page.meta_legend">
<source>Metadata</source>
</trans-unit>
<trans-unit id="tl_page.canonical_legend">
<source>Canonical URL</source>
</trans-unit>
<trans-unit id="tl_page.system_legend">
<source>System settings</source>
</trans-unit>
Expand Down
24 changes: 12 additions & 12 deletions core-bundle/src/Resources/contao/models/PageModel.php
Expand Up @@ -50,6 +50,9 @@
* @property string|null $favicon
* @property string|null $robotsTxt
* @property string $mailerTransport
* @property string|integer $enableCanonical
* @property string $canonicalLink
* @property string $canonicalKeepParams
* @property string $adminEmail
* @property string $dateFormat
* @property string $timeFormat
Expand Down Expand Up @@ -85,9 +88,6 @@
* @property string|integer $stop
* @property string|boolean $enforceTwoFactor
* @property string|integer $twoFactorJumpTo
* @property string|integer $enableCanonical
* @property string $canonicalLink
* @property string $canonicalKeepParams
*
* @property array $trail
* @property string $mainAlias
Expand Down Expand Up @@ -144,6 +144,9 @@
* @method static PageModel|null findOneByFavicon($val, array $opt=array())
* @method static PageModel|null findOneByRobotsTxt($val, array $opt=array())
* @method static PageModel|null findOneByMailerTransport($val, array $opt=array())
* @method static PageModel|null findOneByEnableCanonical($val, array $opt=array())
* @method static PageModel|null findOneByCanonicalLink($val, array $opt=array())
* @method static PageModel|null findOneByCanonicalKeepParams($val, array $opt=array())
* @method static PageModel|null findOneByAdminEmail($val, array $opt=array())
* @method static PageModel|null findOneByDateFormat($val, array $opt=array())
* @method static PageModel|null findOneByTimeFormat($val, array $opt=array())
Expand Down Expand Up @@ -176,9 +179,6 @@
* @method static PageModel|null findOneByStop($val, array $opt=array())
* @method static PageModel|null findOneByEnforceTwoFactor($val, array $opt=array())
* @method static PageModel|null findOneByTwoFactorJumpTo($val, array $opt=array())
* @method static PageModel|null findOneByEnableCanonical($val, array $opt=array())
* @method static PageModel|null findOneByCanonicalLink($val, array $opt=array())
* @method static PageModel|null findOneByCanonicalKeepParams($val, array $opt=array())
*
* @method static Collection|PageModel[]|PageModel|null findByPid($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findBySorting($val, array $opt=array())
Expand All @@ -203,6 +203,9 @@
* @method static Collection|PageModel[]|PageModel|null findByFavicon($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByRobotsTxt($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByMailerTransport($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByEnableCanonical($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByCanonicalLink($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByCanonicalKeepParams($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByAdminEmail($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByDateFormat($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByTimeFormat($val, array $opt=array())
Expand Down Expand Up @@ -235,9 +238,6 @@
* @method static Collection|PageModel[]|PageModel|null findByStop($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByEnforceTwoFactor($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByTwoFactorJumpTo($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByEnableCanonical($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByCanonicalLink($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByCanonicalKeepParams($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findMultipleByIds($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findBy($col, $val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findAll(array $opt=array())
Expand Down Expand Up @@ -266,6 +266,9 @@
* @method static integer countByFavicon($val, array $opt=array())
* @method static integer countByRobotsTxt($val, array $opt=array())
* @method static integer countByMailerTransport($val, array $opt=array())
* @method static integer countByEnableCanonical($val, array $opt=array())
* @method static integer countByCanonicalLink($val, array $opt=array())
* @method static integer countByCanonicalKeepParams($val, array $opt=array())
* @method static integer countByAdminEmail($val, array $opt=array())
* @method static integer countByDateFormat($val, array $opt=array())
* @method static integer countByTimeFormat($val, array $opt=array())
Expand Down Expand Up @@ -298,9 +301,6 @@
* @method static integer countByStop($val, array $opt=array())
* @method static integer countByEnforceTwoFactor($val, array $opt=array())
* @method static integer countByTwoFactorJumpTo($val, array $opt=array())
* @method static integer countByEnableCanonical($val, array $opt=array())
* @method static integer countByCanonicalLink($val, array $opt=array())
* @method static integer countByCanonicalKeepParams($val, array $opt=array())
*
* @author Leo Feyer <https://github.com/leofeyer>
*/
Expand Down
13 changes: 8 additions & 5 deletions core-bundle/src/Resources/contao/pages/PageRegular.php
Expand Up @@ -79,9 +79,10 @@ protected function prepare($objPage)
$locale = LocaleUtil::formatAsLocale($objPage->language);

$container = System::getContainer();
$container->get('translator')->setLocale($locale);

$request = $container->get('request_stack')->getCurrentRequest();
$request->setLocale($locale);
$container->get('translator')->setLocale($locale);

$this->responseContext = $container->get(CoreResponseContextFactory::class)->createContaoWebpageResponseContext($objPage);

Expand Down Expand Up @@ -213,21 +214,23 @@ protected function prepare($objPage)
}
}

$headBag = $this->responseContext->get(HtmlHeadBag::class);

// Set the page title and description AFTER the modules have been generated
$this->Template->mainTitle = $objPage->rootPageTitle;
$this->Template->pageTitle = htmlspecialchars($this->responseContext->get(HtmlHeadBag::class)->getTitle());
$this->Template->pageTitle = htmlspecialchars($headBag->getTitle());

// Remove shy-entities (see #2709)
$this->Template->mainTitle = str_replace('[-]', '', $this->Template->mainTitle);
$this->Template->pageTitle = str_replace('[-]', '', $this->Template->pageTitle);

// Meta robots tag
$this->Template->robots = $this->responseContext->get(HtmlHeadBag::class)->getMetaRobots();
$this->Template->robots = $headBag->getMetaRobots();

// Canonical
if ($objPage->enableCanonical)
{
$this->Template->canonical = $this->responseContext->get(HtmlHeadBag::class)->getCanonicalUriForRequest($request);
$this->Template->canonical = $headBag->getCanonicalUriForRequest($request);
}

// Fall back to the default title tag
Expand All @@ -238,7 +241,7 @@ protected function prepare($objPage)

// Assign the title and description
$this->Template->title = strip_tags($this->replaceInsertTags($objLayout->titleTag));
$this->Template->description = htmlspecialchars($this->responseContext->get(HtmlHeadBag::class)->getMetaDescription());
$this->Template->description = htmlspecialchars($headBag->getMetaDescription());

// Body onload and body classes
$this->Template->onload = trim($objLayout->onload);
Expand Down

0 comments on commit 06ea58a

Please sign in to comment.