Skip to content

Commit

Permalink
SW-19286 - Made target-attribute fully customizable, refinements afte…
Browse files Browse the repository at this point in the history
…r code review
  • Loading branch information
Dominic Klein committed Jul 18, 2017
1 parent bf82453 commit 6b3ecf4
Show file tree
Hide file tree
Showing 16 changed files with 179 additions and 39 deletions.
15 changes: 15 additions & 0 deletions UPGRADE-5.3.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@ View all changes from v5.3.0-RC1...v5.3.0-RC2](https://github.com/shopware/shopw
* Added smarty blocks `frontend_checkout_shipping_payment_core_button_top` and `frontend_checkout_shipping_payment_core_button_top` for shipping
* Added new Interface for facet result template switch `Shopware\Bundle\SearchBundle\TemplateSwitchable`
* Added new service `Shopware\Bundle\MediaBundle\CdnOptimizerService` for optimizing remote images on CDNs
* Added option to control target attribute for external links in categories
* Added database column `s_category.external_target`
* Added property `externalTarget` in `Shopware\Bundle\StoreFrontBundle\Struct\Category`
* Added property `externalTarget` in `Shopware\Models\Category\Category`
* Added property `externalTarget` in `Shopware\themes\Backend\ExtJs\backend\category\model\detail`
* Added translations for field labels and combo box options

### Changes

Expand Down Expand Up @@ -227,6 +233,15 @@ View all changes from v5.3.0-RC1...v5.3.0-RC2](https://github.com/shopware/shopw
* Refactored backend customer module. Please take a look into the different template files to see what has changed.
* Changed parameter order of `Shopware\Bundle\SearchBundle\FacetResult\RangeFacetResult::__construct()` and added `$suffix` and `$digits`.
* Changed selection fields in the voucher module. `shopware-form-field-single-selection` is now used instead of the native `combobox` xtype and `shopware-form-field-product-grid` is used for article restriction.
* Changed templates to support custom targets for category links
* `themes/Frontend/Bare/frontend/index/main-navigation.tpl`
* `themes/Frontend/Bare/frontend/index/sidebar-categories.tpl`
* `themes/Frontend/Bare/frontend/sitemap/index.tpl`
* `themes/Frontend/Bare/frontend/sitemap/recurse.tpl`
* `engine/Shopware/Plugins/Default/Frontend/AdvancedMenu/Views/frontend/advanced_menu/index.tpl`
* Changed `engine\Shopware\Bundle\StoreFrontBundle\Gateway\DBAL\Hydrator\CategoryHydrator` to support the custom target property
* Changed `engine\Shopware\Bundle\StoreFrontBundle\Gateway\DBAL\FieldHelper` to support the custom target property
* Changed `engine\Shopware\Components\Compatibility\LegacyStructConverter` to support the custom target property

### Removals

Expand Down
36 changes: 36 additions & 0 deletions _sql/migrations/945-add-category-column-external-target.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/**
* Shopware 5
* Copyright (c) shopware AG
*
* According to our dual licensing model, this program can be used either
* under the terms of the GNU Affero General Public License, version 3,
* or under a proprietary license.
*
* The texts of the GNU Affero General Public License with an additional
* permission and of our proprietary license can be found at and
* in the LICENSE file you have received along with this program.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* "Shopware" is a registered trademark of shopware AG.
* The licensing of the program under the AGPLv3 does not imply a
* trademark license. Therefore any rights, title and interest in
* our trademarks remain entirely with us.
*/

use Shopware\Components\Migrations\AbstractMigration;

class Migrations_Migration945 extends AbstractMigration
{
public function up($modus)
{
$sql = <<<'EOD'
ALTER TABLE `s_categories` ADD `external_target` VARCHAR(32) DEFAULT "";
EOD;
$this->addSql($sql);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ public function getCategoryFields()
'category.template as __category_template',
'category.blog as __category_blog',
'category.external as __category_external',
'category.external_target as __category_external_target',
'category.hidefilter as __category_hidefilter',
'category.hidetop as __category_hidetop',
'category.stream_id as __category_stream_id',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ private function assignCategoryData(Struct\Category $category, array $data)
$category->setExternalLink($data['__category_external']);
}

if (isset($data['__category_external_target'])) {
$category->setExternalTarget($data['__category_external_target']);
}

if (isset($data['__category_hidefilter'])) {
$category->setDisplayFacets((bool) !$data['__category_hidefilter']);
}
Expand Down
21 changes: 21 additions & 0 deletions engine/Shopware/Bundle/StoreFrontBundle/Struct/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ class Category extends Extendable implements \JsonSerializable
*/
protected $externalLink;

/**
* @var string
*/
protected $externalTarget;

/**
* @var Media
*/
Expand Down Expand Up @@ -320,6 +325,22 @@ public function getExternalLink()
return $this->externalLink;
}

/**
* @param string $externalTarget
*/
public function setExternalTarget($externalTarget)
{
$this->externalTarget = $externalTarget;
}

/**
* @return string
*/
public function getExternalTarget()
{
return $this->externalTarget;
}

/**
* @param bool $displayFacets
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ public function convertCategoryStruct(StoreFrontBundle\Struct\Category $category
'blog' => $category->isBlog(),
'path' => $categoryPath,
'external' => $category->getExternalLink(),
'externalTarget' => $category->getExternalTarget(),
'hideFilter' => !$category->displayFacets(),
'hideTop' => !$category->displayInNavigation(),
'changed' => null,
Expand Down
1 change: 1 addition & 0 deletions engine/Shopware/Core/sCategories.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ public function convertCategory(Category $category, $childrenCounts)
'blog' => $category->isBlog(),
'path' => $path,
'external' => $category->getExternalLink(),
'externalTarget' => $category->getExternalTarget(),
'hideFilter' => !$category->displayFacets(),
'hideTop' => !$category->displayInNavigation(),
'hidetop' => !$category->displayInNavigation(),
Expand Down
29 changes: 29 additions & 0 deletions engine/Shopware/Models/Category/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,15 @@ class Category extends ModelEntity
*/
private $external;

/**
* Where to open the external category page? "_blank" or "_parent"
*
* @var string
*
* @ORM\Column(name="external_target", type="text", nullable=false)
*/
private $externalTarget = '';

/**
* Should any filter shown on the category page be hidden?
*
Expand Down Expand Up @@ -753,6 +762,26 @@ public function getExternal()
return $this->external;
}

/**
* Gets the flag if external source is opened in a new window
*
* @return string
*/
public function getExternalTarget()
{
return $this->externalTarget;
}

/**
* Sets the flag if external source is opened in a new window
*
* @param string $externalTarget
*/
public function setExternalTarget($externalTarget)
{
$this->externalTarget = $externalTarget;
}

/**
* Set the flag which hides the filter
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

<li class="menu--list-item item--level-{$level}"{if $level === 0} style="width: 100%"{/if}>
{block name="frontend_plugins_advanced_menu_list_item"}
<a href="{$categoryLink|escapeHtml}" class="menu--list-item-link" title="{$category.name|escape}">{$category.name}</a>
<a href="{$categoryLink|escapeHtml}" class="menu--list-item-link" title="{$category.name|escape}"{if $category.external} target="{$category.externalTarget}"{/if}>{$category.name}</a>

{if $category.sub}
{call name=categories_top categories=$category.sub level=$level+1}
Expand Down Expand Up @@ -49,7 +49,7 @@
{block name="frontend_plugins_advanced_menu_main_container"}
<div class="button-container">
{block name="frontend_plugins_advanced_menu_button_category"}
<a href="{$link|escapeHtml}" class="button--category" title="{s name="toCategoryBtn" namespace="frontend/plugins/advanced_menu/advanced_menu"}{/s}{$mainCategory.name|escape:'html'}">
<a href="{$link|escapeHtml}" class="button--category" title="{s name="toCategoryBtn" namespace="frontend/plugins/advanced_menu/advanced_menu"}{/s}{$mainCategory.name|escape:'html'}"{if $mainCategory.external} target="{$mainCategory.externalTarget}"{/if}>
<i class="icon--arrow-right"></i>
{s name="toCategoryBtn" namespace="frontend/plugins/advanced_menu/advanced_menu"}{/s}{$mainCategory.name}
</a>
Expand Down Expand Up @@ -77,7 +77,7 @@
{/if}
<div class="menu--teaser"{if $hasCategories} style="width: {$columnAmount * 25}%;"{else} style="width: 100%;"{/if}>
{if !empty($mainCategory.media)}
<a href="{$link|escapeHtml}" title="{s name="toCategoryBtn" namespace="frontend/plugins/advanced_menu/advanced_menu"}{/s}{$mainCategory.name|escape:'html'}" class="teaser--image" style="background-image: url({link file={$mainCategory.media.path}});"></a>
<a href="{$link|escapeHtml}" title="{s name="toCategoryBtn" namespace="frontend/plugins/advanced_menu/advanced_menu"}{/s}{$mainCategory.name|escape:'html'}" class="teaser--image" style="background-image: url({link file={$mainCategory.media.path}});"{if $mainCategory.external} target="{$mainCategory.externalTarget}"{/if}></a>
{/if}

{if !empty($mainCategory.cmsHeadline)}
Expand Down
6 changes: 6 additions & 0 deletions snippets/backend/category/main.ini
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ view/settings_default_settings_image_label = "Image"
view/settings_default_settings_image_support_text = "You can use this image for individual template changes. This includes, for instance, the illustration of your category."
view/settings_default_settings_link_external_page_help = "The URL must begin with http://"
view/settings_default_settings_link_external_page_label = "Link to an external site"
view/settings_default_settings_link_external_page_target = "Link target"
view/settings_default_settings_link_external_page_target_self = "_parent"
view/settings_default_settings_link_external_page_target_blank = "_blank"
view/settings_default_settings_name_label = "Description"
view/settings_default_settings_no_design_switch_label = "Disable display switching in frontend."
view/settings_default_settings_no_filter_label = "Hide filters."
Expand Down Expand Up @@ -196,6 +199,9 @@ view/settings_default_settings_image_label = "Bild"
view/settings_default_settings_image_support_text = "Dieses Bild können Sie für Ihre individuelle Templateanpassung nutzen. Sie können es bspw. zur Bebilderung Ihrer Kategorie verwenden."
view/settings_default_settings_link_external_page_help = "Die URL muss mit http:// beginnen"
view/settings_default_settings_link_external_page_label = "Auf externe Seite verlinken"
view/settings_default_settings_link_external_page_target = "Link-Ziel"
view/settings_default_settings_link_external_page_target_self = "_parent"
view/settings_default_settings_link_external_page_target_blank = "_blank"
view/settings_default_settings_name_label = "Bezeichnung"
view/settings_default_settings_no_design_switch_label = "Darstellungswechsel deaktiveren"
view/settings_default_settings_no_filter_label = "Filter ausblenden"
Expand Down
1 change: 1 addition & 0 deletions themes/Backend/ExtJs/backend/category/model/detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ Ext.define('Shopware.apps.Category.model.Detail', {
{ name : 'active', type: 'boolean' },
{ name : 'blog', type: 'boolean' },
{ name : 'external', type: 'string' , useNull:true, defaultValue: null},
{ name : 'externalTarget', type: 'string', defaultValue: '' },
{ name : 'hideFilter', type: 'boolean' },
{ name : 'hideTop', type: 'boolean' },
{ name : 'imagePath', type: 'string' , useNull:true, defaultValue: null},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@
*/
//{block name="backend/category/view/tabs/settings"}
Ext.define('Shopware.apps.Category.view.category.tabs.Settings', {
/**
* Parent Element Ext.container.Container
* @string
*/
/**
* Parent Element Ext.container.Container
* @string
*/
extend:'Ext.form.Panel',
/**
* Register the alias for this class.
Expand Down Expand Up @@ -67,7 +67,7 @@ Ext.define('Shopware.apps.Category.view.category.tabs.Settings', {
* @boolean
*/
autoShow : true,
/**
/**
* enable auto scroll
* @boolean
*/
Expand Down Expand Up @@ -106,6 +106,9 @@ Ext.define('Shopware.apps.Category.view.category.tabs.Settings', {
defaultSettingsNameLabel : '{s name=view/settings_default_settings_name_label}Description{/s}',
defaultSettingsLinkExternalPageLabel : '{s name=view/settings_default_settings_link_external_page_label}Link to an external site{/s}',
defaultSettingsLinkExternalPageHelp : '{s name=view/settings_default_settings_link_external_page_help}The URL must begin with: http://{/s}',
defaultSettingsLinkExternalPageTarget : '{s name=view/settings_default_settings_link_external_page_target}Target for external site{/s}',
defaultSettingsLinkExternalPageTargetSelf : '{s name=view/settings_default_settings_link_external_page_target_self}Same window (default){/s}',
defaultSettingsLinkExternalPageTargetBlank : '{s name=view/settings_default_settings_link_external_page_target_blank}New window{/s}',

defaultSettingsImageLabel : '{s name=view/settings_default_settings_image_label}Image{/s}',
defaultSettingsImageButtonText : '{s name=view/settings_default_settings_image_button_text}Select an image{/s}',
Expand Down Expand Up @@ -222,18 +225,18 @@ Ext.define('Shopware.apps.Category.view.category.tabs.Settings', {
registerEvents: function() {
var me = this;
/**
* Event will be fired when a record is loaded into the settings form.
*
* This event can easily be captured in the controller
* eg.
* <code>
* this.control({ 'recordloaded' : function(){
* Event will be fired when a record is loaded into the settings form.
*
* This event can easily be captured in the controller
* eg.
* <code>
* this.control({ 'recordloaded' : function(){
* console.log('New recored has been loaded.');
* }
* </code>
*
* @event recordloaded
*/
* @event recordloaded
*/
me.addEvents('recordloaded');
},

Expand Down Expand Up @@ -414,6 +417,22 @@ Ext.define('Shopware.apps.Category.view.category.tabs.Settings', {
dataIndex:'external',
name:'external'
},
{
fieldLabel: me.snippets.defaultSettingsLinkExternalPageTarget,
xtype: 'combo',
name: 'externalTarget',
valueField: 'externalTarget',
displayField: 'externalTarget',
anchor: '100%',
allowBlank: true,
store: new Ext.data.SimpleStore({
fields: ['externalTarget'],
data: [
[me.snippets.defaultSettingsLinkExternalPageTargetSelf],
[me.snippets.defaultSettingsLinkExternalPageTargetBlank]
]
})
},
{
xtype:'mediaselectionfield',
fieldLabel:me.snippets.defaultSettingsImageLabel,
Expand Down Expand Up @@ -504,18 +523,18 @@ Ext.define('Shopware.apps.Category.view.category.tabs.Settings', {
defaults : me.defaults,
disabled : true,
items : [{
xtype : 'textfield',
fieldLabel : me.snippets.metaTitle,
name : 'metaTitle'
},{
xtype : 'textareafield',
fieldLabel : me.snippets.metaDescription,
name : 'metaDescription'
}, {
xtype : 'textfield',
fieldLabel : me.snippets.metaKeywords,
name : 'metaKeywords'
}
xtype : 'textfield',
fieldLabel : me.snippets.metaTitle,
name : 'metaTitle'
},{
xtype : 'textareafield',
fieldLabel : me.snippets.metaDescription,
name : 'metaDescription'
}, {
xtype : 'textfield',
fieldLabel : me.snippets.metaKeywords,
name : 'metaKeywords'
}
]
});
},
Expand Down
2 changes: 1 addition & 1 deletion themes/Frontend/Bare/frontend/index/main-navigation.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
{if !$sCategory.hideTop}
<li class="navigation--entry{if $sCategory.flag} is--active{/if}" role="menuitem">
{block name='frontend_index_navigation_categories_top_link'}
<a class="navigation--link{if $sCategory.flag} is--active{/if}" href="{$sCategory.link}" title="{$sCategory.description}" itemprop="url">
<a class="navigation--link{if $sCategory.flag} is--active{/if}" href="{$sCategory.link}" title="{$sCategory.description}" itemprop="url"{if $sCategory.external} target="{$sCategory.externalTarget}"{/if}>
<span itemprop="name">{$sCategory.description}</span>
</a>
{/block}
Expand Down
3 changes: 2 additions & 1 deletion themes/Frontend/Bare/frontend/index/sidebar-categories.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
href="{$category.link}"
data-categoryId="{$category.id}"
data-fetchUrl="{url module=widgets controller=listing action=getCategory categoryId={$category.id}}"
title="{$category.description|escape}">
title="{$category.description|escape}"
{if $category.external}target="{$category.externalTarget}"{/if}>
{$category.description}

{if $category.childrenCount}
Expand Down
2 changes: 1 addition & 1 deletion themes/Frontend/Bare/frontend/sitemap/index.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
{/block}
{else}
{block name="frontend_sitemap_navigation_defaultpages"}
<a href="{$categoryTree.link}" title="{$categoryTree.name|escape}" class="sitemap--navigation-head-link is--active">
<a href="{$categoryTree.link}" title="{$categoryTree.name|escape}" class="sitemap--navigation-head-link is--active"{if $categoryTree.external} target="{$categoryTree.externalTarget}"{/if}>
{$categoryTree.name}
</a>
{/block}
Expand Down
Loading

0 comments on commit 6b3ecf4

Please sign in to comment.