Browse code

Rewrite ajax functionality for Contao 4 compatibility

Benjamin Roth authored on22/03/2019 20:54:43
Showing1 changed files
... ...
@@ -70,7 +70,11 @@ $GLOBALS['TL_DCA']['tl_page']['fields']['es_ext_agecheck_title'] = array
70 70
   'label'                   => &$GLOBALS['TL_LANG']['tl_page']['es_ext_agecheck_title'],
71 71
   'exclude'                 => true,
72 72
   'inputType'               => 'text',
73
-  'eval'                    => array('mandatory'=>true, 'rgxp'=>'extnd'),
73
+  'load_callback'            => array
74
+  (
75
+    array('tl_page_legalAgeCheck', 'setDefaultLegalAgeTitle')
76
+  ),
77
+  'eval'                    => array('mandatory'=>true, 'rgxp'=>'extnd','alwaysSave'=>true),
74 78
   'sql'                     => "varchar(255) NOT NULL default ''"
75 79
 );
76 80
 
... ...
@@ -109,4 +113,21 @@ class tl_page_legalAgeCheck extends \Backend
109 113
 
110 114
     return $varValue;
111 115
   }
116
+
117
+  /**
118
+   * Return default title if value is empty
119
+   *
120
+   * @param $varValue
121
+   * @param \DataContainer $dc
122
+   * @return String
123
+   */
124
+  public function setDefaultLegalAgeTitle($varValue, \DataContainer $dc)
125
+  {
126
+    if (!$varValue)
127
+    {
128
+      return $GLOBALS['TL_LANG']['MSC']['es_legalagecheck']['title'];
129
+    }
130
+
131
+    return $varValue;
132
+  }
112 133
 }
113 134
\ No newline at end of file
Browse code

Add customization fields for the displayed text.

Benjamin Roth authored on22/03/2019 16:56:28
Showing1 changed files
... ...
@@ -35,7 +35,7 @@
35 35
 $GLOBALS['TL_DCA']['tl_page']['palettes']['root'] = str_replace('{meta_legend}', '{agecheck_legend:hide},es_ext_agecheck;{meta_legend}',$GLOBALS['TL_DCA']['tl_page']['palettes']['root']);
36 36
 $GLOBALS['TL_DCA']['tl_page']['palettes']['regular'] = str_replace('{meta_legend}', '{agecheck_legend:hide},es_ext_agecheck_ignorePage;{meta_legend}',$GLOBALS['TL_DCA']['tl_page']['palettes']['regular']);
37 37
 $GLOBALS['TL_DCA']['tl_page']['palettes']['__selector__'][] = 'es_ext_agecheck';
38
-$GLOBALS['TL_DCA']['tl_page']['subpalettes']['es_ext_agecheck'] = 'es_ext_agecheck_exitPage';
38
+$GLOBALS['TL_DCA']['tl_page']['subpalettes']['es_ext_agecheck'] = 'es_ext_agecheck_exitPage,es_ext_agecheck_title,es_ext_agecheck_text';
39 39
 /**
40 40
  * Fields
41 41
  */
... ...
@@ -63,4 +63,50 @@ $GLOBALS['TL_DCA']['tl_page']['fields']['es_ext_agecheck_ignorePage'] = array
63 63
 	'exclude'                 => true,
64 64
 	'inputType'               => 'checkbox',
65 65
   'sql'                     => "char(1) NOT NULL default ''"
66
-);
67 66
\ No newline at end of file
67
+);
68
+
69
+$GLOBALS['TL_DCA']['tl_page']['fields']['es_ext_agecheck_title'] = array
70
+(
71
+  'label'                   => &$GLOBALS['TL_LANG']['tl_page']['es_ext_agecheck_title'],
72
+  'exclude'                 => true,
73
+  'inputType'               => 'text',
74
+  'eval'                    => array('mandatory'=>true, 'rgxp'=>'extnd'),
75
+  'sql'                     => "varchar(255) NOT NULL default ''"
76
+);
77
+
78
+$GLOBALS['TL_DCA']['tl_page']['fields']['es_ext_agecheck_text'] = array
79
+(
80
+  'label'                   => &$GLOBALS['TL_LANG']['tl_page']['es_ext_agecheck_text'],
81
+  'exclude'                 => true,
82
+  'inputType'               => 'textarea',
83
+  'load_callback'            => array
84
+  (
85
+    array('tl_page_legalAgeCheck', 'setDefaultLegalAgeText')
86
+  ),
87
+  'save_callback'            => array
88
+  (
89
+    array('tl_page_legalAgeCheck', 'setDefaultLegalAgeText')
90
+  ),
91
+  'eval'                    => array('rte'=>'tinyMCE', 'minlen'=>1, 'allowHtml'=>true),
92
+  'sql'                     => "text NULL"
93
+);
94
+
95
+class tl_page_legalAgeCheck extends \Backend
96
+{
97
+  /**
98
+   * Return default text if value is empty
99
+   *
100
+   * @param $varValue
101
+   * @param \DataContainer $dc
102
+   * @return String
103
+   */
104
+  public function setDefaultLegalAgeText($varValue, \DataContainer $dc)
105
+  {
106
+    if (!$varValue)
107
+    {
108
+      return $GLOBALS['TL_LANG']['MSC']['es_legalagecheck']['text'];
109
+    }
110
+
111
+    return $varValue;
112
+  }
113
+}
68 114
\ No newline at end of file
Browse code

Move sql into DCA

Benjamin Roth authored on21/03/2019 09:09:41
Showing1 changed files
... ...
@@ -44,7 +44,8 @@ $GLOBALS['TL_DCA']['tl_page']['fields']['es_ext_agecheck'] = array
44 44
 	'label'                   => &$GLOBALS['TL_LANG']['tl_page']['es_ext_agecheck'],
45 45
 	'exclude'                 => true,
46 46
 	'inputType'               => 'checkbox',
47
-	'eval'                    => array('submitOnChange'=>true)
47
+	'eval'                    => array('submitOnChange'=>true),
48
+  'sql'                     => "char(1) NOT NULL default ''"
48 49
 );
49 50
 
50 51
 $GLOBALS['TL_DCA']['tl_page']['fields']['es_ext_agecheck_exitPage'] = array
... ...
@@ -52,12 +53,14 @@ $GLOBALS['TL_DCA']['tl_page']['fields']['es_ext_agecheck_exitPage'] = array
52 53
 	'label'                   => &$GLOBALS['TL_LANG']['tl_page']['es_ext_agecheck_exitPage'],
53 54
 	'exclude'                 => true,
54 55
 	'inputType'               => 'pageTree',
55
-	'eval'                    => array('fieldType'=>'radio', 'mandatory'=>true)
56
+	'eval'                    => array('fieldType'=>'radio', 'mandatory'=>true),
57
+  'sql'                     => "int(10) unsigned NOT NULL default '0'"
56 58
 );
57 59
 
58 60
 $GLOBALS['TL_DCA']['tl_page']['fields']['es_ext_agecheck_ignorePage'] = array
59 61
 (
60 62
 	'label'                   => &$GLOBALS['TL_LANG']['tl_page']['es_ext_agecheck_ignorePage'],
61 63
 	'exclude'                 => true,
62
-	'inputType'               => 'checkbox'
64
+	'inputType'               => 'checkbox',
65
+  'sql'                     => "char(1) NOT NULL default ''"
63 66
 );
64 67
\ No newline at end of file
Browse code

Initial commit

Benjamin Roth authored on21/03/2019 09:05:45
Showing1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,63 @@
1
+<?php if (!defined('TL_ROOT')) die('You can not access this file directly!');
2
+
3
+/**
4
+ * Contao Open Source CMS
5
+ * Copyright (C) 2005-2011 Leo Feyer
6
+ *
7
+ * Formerly known as TYPOlight Open Source CMS.
8
+ *
9
+ * This program is free software: you can redistribute it and/or
10
+ * modify it under the terms of the GNU Lesser General Public
11
+ * License as published by the Free Software Foundation, either
12
+ * version 3 of the License, or (at your option) any later version.
13
+ * 
14
+ * This program is distributed in the hope that it will be useful,
15
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
+ * Lesser General Public License for more details.
18
+ * 
19
+ * You should have received a copy of the GNU Lesser General Public
20
+ * License along with this program. If not, please visit the Free
21
+ * Software Foundation website at <http://www.gnu.org/licenses/>.
22
+ *
23
+ * PHP version 5
24
+ * @copyright  eSales Media 2012 
25
+ * @author     Benjamin Roth <www.esales-media.de> 
26
+ * @package    legalAgeCheck 
27
+ * @license    GNU/LGPL
28
+ * @filesource
29
+ */
30
+
31
+
32
+/**
33
+ * Palettes
34
+ */
35
+$GLOBALS['TL_DCA']['tl_page']['palettes']['root'] = str_replace('{meta_legend}', '{agecheck_legend:hide},es_ext_agecheck;{meta_legend}',$GLOBALS['TL_DCA']['tl_page']['palettes']['root']);
36
+$GLOBALS['TL_DCA']['tl_page']['palettes']['regular'] = str_replace('{meta_legend}', '{agecheck_legend:hide},es_ext_agecheck_ignorePage;{meta_legend}',$GLOBALS['TL_DCA']['tl_page']['palettes']['regular']);
37
+$GLOBALS['TL_DCA']['tl_page']['palettes']['__selector__'][] = 'es_ext_agecheck';
38
+$GLOBALS['TL_DCA']['tl_page']['subpalettes']['es_ext_agecheck'] = 'es_ext_agecheck_exitPage';
39
+/**
40
+ * Fields
41
+ */
42
+$GLOBALS['TL_DCA']['tl_page']['fields']['es_ext_agecheck'] = array
43
+(
44
+	'label'                   => &$GLOBALS['TL_LANG']['tl_page']['es_ext_agecheck'],
45
+	'exclude'                 => true,
46
+	'inputType'               => 'checkbox',
47
+	'eval'                    => array('submitOnChange'=>true)
48
+);
49
+
50
+$GLOBALS['TL_DCA']['tl_page']['fields']['es_ext_agecheck_exitPage'] = array
51
+(
52
+	'label'                   => &$GLOBALS['TL_LANG']['tl_page']['es_ext_agecheck_exitPage'],
53
+	'exclude'                 => true,
54
+	'inputType'               => 'pageTree',
55
+	'eval'                    => array('fieldType'=>'radio', 'mandatory'=>true)
56
+);
57
+
58
+$GLOBALS['TL_DCA']['tl_page']['fields']['es_ext_agecheck_ignorePage'] = array
59
+(
60
+	'label'                   => &$GLOBALS['TL_LANG']['tl_page']['es_ext_agecheck_ignorePage'],
61
+	'exclude'                 => true,
62
+	'inputType'               => 'checkbox'
63
+);
0 64
\ No newline at end of file