Skip to content

Commit b1611c8

Browse files
authored
Merge pull request #43 from aarongerig/1.x
[HtmlTagIntegrator] Add presets (V1)
2 parents cf851a9 + f956760 commit b1611c8

File tree

6 files changed

+133
-29
lines changed

6 files changed

+133
-29
lines changed

UPGRADE.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ Just click the "update" button or execute the migration command to finish the bu
88

99
***
1010

11+
#### Version 1.2
12+
- Support Pimcore 6.9 only
13+
- Add presets to HTML tag integrator [#43](https://github.com/dachcom-digital/pimcore-seo/pull/43)
14+
1115
#### Update from Version 1.1.0 to Version 1.1.1
1216
- **[ENHANCEMENT]** Improve Dependency Check [#20](https://github.com/dachcom-digital/pimcore-seo/issues/20)
1317

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
},
3636
"require": {
3737
"google/apiclient": "^2.0",
38-
"pimcore/pimcore": "^6.0",
38+
"pimcore/pimcore": "^6.9",
3939
"doctrine/orm": "^2.7"
4040
},
4141
"require-dev": {

docs/MetaData/Integrator/14_HtmlTagIntegrator.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,34 @@ seo:
1414
enabled_integrator:
1515
- integrator_name: html_tag
1616
```
17+
18+
## Extended Configuration
19+
20+
```yaml
21+
seo:
22+
meta_data_configuration:
23+
meta_data_integrator:
24+
enabled_integrator:
25+
- integrator_name: html_tag
26+
integrator_config:
27+
presets_only_mode: false
28+
presets:
29+
-
30+
label: 'Robots No-Index'
31+
value: '<meta name="robots" content="noindex, nofollow">'
32+
icon_class: 'pimcore_icon_stop'
33+
-
34+
label: 'Secret Meta-Link'
35+
value: '<meta name="secret" content="secret-thing">'
36+
```
37+
38+
### presets
39+
If defined, the user is able to add predefined presets. They can only be added and not edited!
40+
41+
![image](https://user-images.githubusercontent.com/700119/202385523-b748a0d3-56c3-4403-980f-53c60c2b45e8.png)
42+
43+
![image](https://user-images.githubusercontent.com/700119/202278570-51d1ed18-e323-4704-b0d7-09649fca2281.png)
44+
45+
### presets_only_mode
46+
If set to `true`, the user is not able to add custom tags but only presets:
47+
![image](https://user-images.githubusercontent.com/700119/202385300-61f5d884-8d4f-4353-8c0f-5cc6c79a7b7c.png)

src/SeoBundle/MetaData/Integrator/HtmlTagIntegrator.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ public function getBackendConfiguration($element)
2020
return [
2121
'hasLivePreview' => false,
2222
'livePreviewTemplates' => [],
23-
'useLocalizedFields' => false
23+
'useLocalizedFields' => false,
24+
'presets' => $this->configuration['presets'],
25+
'presets_only_mode' => $this->configuration['presets_only_mode'],
2426
];
2527
}
2628

@@ -102,6 +104,13 @@ public function setConfiguration(array $configuration)
102104
*/
103105
public static function configureOptions(OptionsResolver $resolver)
104106
{
105-
// no options here.
107+
$resolver->setDefaults([
108+
'presets_only_mode' => false,
109+
'presets' => [],
110+
]);
111+
112+
$resolver->setRequired(['presets_only_mode']);
113+
$resolver->setAllowedTypes('presets_only_mode', ['bool']);
114+
$resolver->setAllowedTypes('presets', ['array']);
106115
}
107116
}

src/SeoBundle/MetaData/MetaDataProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace SeoBundle\MetaData;
44

5-
use Pimcore\Templating\Helper\HeadMeta;
6-
use Pimcore\Templating\Helper\HeadTitle;
5+
use Pimcore\Twig\Extension\Templating\HeadMeta;
6+
use Pimcore\Twig\Extension\Templating\HeadTitle;
77
use SeoBundle\MetaData\Extractor\ExtractorInterface;
88
use SeoBundle\Middleware\MiddlewareDispatcherInterface;
99
use SeoBundle\Registry\MetaDataExtractorRegistryInterface;

src/SeoBundle/Resources/public/js/metaData/integrator/htmlTagIntegrator.js

Lines changed: 84 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ pimcore.registerNS('Seo.MetaData.Integrator.HtmlTagIntegrator');
22
Seo.MetaData.Integrator.HtmlTagIntegrator = Class.create(Seo.MetaData.Integrator.AbstractIntegrator, {
33

44
fieldSetTitle: t('seo_bundle.integrator.html.title') + ' (&lt;meta .../&gt; &lt;link .../&gt; ...)',
5+
addPresetButtonLabel: t('seo_bundle.integrator.property.add_preset'),
56
iconClass: 'seo_integrator_icon_html_tags',
67
htmlTagPanel: null,
78

@@ -30,52 +31,109 @@ Seo.MetaData.Integrator.HtmlTagIntegrator = Class.create(Seo.MetaData.Integrator
3031
}
3132

3233
Ext.Array.each(this.data, function (htmlTagValue) {
33-
this.addHtmlTagField(htmlTagValue);
34+
var presetData = this.getPresetByValue(htmlTagValue);
35+
this.addHtmlTagField(
36+
htmlTagValue,
37+
presetData !== null,
38+
presetData !== null && presetData.hasOwnProperty('label') ? presetData.label : null
39+
);
3440
}.bind(this));
3541
},
3642

3743
getAddControl: function () {
3844

3945
var items = [],
46+
presetMenu = [],
47+
configuration = this.getConfiguration(),
48+
availablePresets = configuration.hasOwnProperty('presets') ? configuration.presets : [],
49+
presetsOnlyMode = configuration.hasOwnProperty('presets_only_mode') ? configuration.presets_only_mode : false,
4050
user = pimcore.globalmanager.get('user');
4151

42-
if(user.isAllowed('seo_bundle_add_property') === false) {
52+
if (user.isAllowed('seo_bundle_add_property') === false) {
4353
return [];
4454
}
4555

46-
items.push({
47-
cls: 'pimcore_block_button_plus',
48-
text: t('seo_bundle.integrator.html.add_field'),
49-
iconCls: 'pimcore_icon_plus',
50-
handler: this.addHtmlTagField.bind(this, null, null)
51-
});
56+
if (presetsOnlyMode === false) {
57+
items.push({
58+
cls: 'pimcore_block_button_plus',
59+
text: t('seo_bundle.integrator.html.add_field'),
60+
iconCls: 'pimcore_icon_plus',
61+
handler: this.addHtmlTagField.bind(this, null, null, null)
62+
});
63+
}
5264

53-
items.push({
54-
xtype: 'container',
55-
flex: 1,
56-
html: t('seo_bundle.integrator.html.caution_note'),
57-
style: {
58-
padding: '5px',
59-
border: '1px solid #b32d2d',
60-
background: '#e8acac',
61-
margin: '0 0 10px 0',
62-
color: 'black'
63-
}
64-
});
65+
if (availablePresets.length > 0) {
66+
67+
Ext.Array.each(availablePresets, function (preset) {
68+
69+
var label = preset.hasOwnProperty('label') ? preset.label : ('Preset ' + index),
70+
icon = preset.hasOwnProperty('icon_class') && preset.icon_class !== null ? preset.icon_class : 'pimcore_icon_brick';
71+
72+
presetMenu.push({
73+
text: label,
74+
iconCls: icon,
75+
handler: this.addHtmlTagField.bind(this, preset.hasOwnProperty('value') ? preset.value : '#', true, label)
76+
});
77+
78+
}.bind(this));
79+
80+
items.push({
81+
cls: 'pimcore_block_button_plus',
82+
text: this.addPresetButtonLabel,
83+
iconCls: 'pimcore_icon_objectbricks',
84+
menu: presetMenu
85+
});
86+
}
87+
88+
if (presetsOnlyMode === false) {
89+
items.push({
90+
xtype: 'container',
91+
flex: 1,
92+
html: t('seo_bundle.integrator.html.caution_note'),
93+
style: {
94+
padding: '5px',
95+
border: '1px solid #b32d2d',
96+
background: '#e8acac',
97+
margin: '0 0 10px 0',
98+
color: 'black'
99+
}
100+
});
101+
}
65102

66103
return new Ext.Toolbar({
67104
items: items
68105
});
69106
},
70107

71-
addHtmlTagField: function (fieldValue) {
108+
getPresetByValue: function (htmlTagValue) {
109+
110+
var presetData = null,
111+
configuration = this.getConfiguration(),
112+
availablePresets = configuration.hasOwnProperty('presets') ? configuration.presets : [];
113+
114+
if (availablePresets.length === 0) {
115+
return null;
116+
}
117+
118+
Ext.Array.each(availablePresets, function (preset) {
119+
if (preset.hasOwnProperty('value') && preset.value === htmlTagValue) {
120+
presetData = preset;
121+
return false;
122+
}
123+
124+
}.bind(this));
125+
126+
return presetData;
127+
},
128+
129+
addHtmlTagField: function (fieldValue, disabled, tagName) {
72130

73131
var itemFieldContainer,
74132
user = pimcore.globalmanager.get('user');
75133

76134
itemFieldContainer = new Ext.form.FieldContainer({
77135
xtype: 'fieldcontainer',
78-
width: 700,
136+
width: 800,
79137
layout: 'hbox',
80138
style: {
81139
marginTop: '5px',
@@ -85,10 +143,12 @@ Seo.MetaData.Integrator.HtmlTagIntegrator = Class.create(Seo.MetaData.Integrator
85143
items: [
86144
{
87145
xtype: 'textfield',
88-
fieldLabel: t('seo_bundle.integrator.html.tag'),
146+
labelWidth: 170,
147+
fieldLabel: Ext.isString(tagName) ? tagName : t('seo_bundle.integrator.html.tag'),
89148
style: 'margin: 0 10px 0 0',
90149
name: 'tags',
91150
value: fieldValue,
151+
readOnly: disabled === true,
92152
flex: 1,
93153
},
94154
{
@@ -135,4 +195,4 @@ Seo.MetaData.Integrator.HtmlTagIntegrator = Class.create(Seo.MetaData.Integrator
135195
getValuesForPreview: function () {
136196
return [];
137197
}
138-
});
198+
});

0 commit comments

Comments
 (0)