File tree Expand file tree Collapse file tree 2 files changed +71
-0
lines changed Expand file tree Collapse file tree 2 files changed +71
-0
lines changed Original file line number Diff line number Diff line change 55
66namespace Geniem \ACF ;
77
8+ use Geniem \ACF \Field \Common \Translatable ;
9+
810/**
911 * Class Field
1012 */
1113abstract class Field {
14+
15+ /**
16+ * Import the translatable functionalities
17+ */
18+ use Translatable;
19+
1220 /**
1321 * Field label.
1422 *
Original file line number Diff line number Diff line change 1+ <?php
2+ /**
3+ * ACF Codifier Translatable trait
4+ */
5+
6+ namespace Geniem \ACF \Field \Common ;
7+
8+ /**
9+ * Translatable trait
10+ */
11+ trait Translatable {
12+ /**
13+ * The field translations value
14+ *
15+ * @var string
16+ */
17+ protected $ translations ;
18+
19+ /**
20+ * Set field translations value
21+ *
22+ * @see https://polylang.pro/doc/working-with-acf-pro/#customize-acf-fields
23+ *
24+ * @throws \Geniem\ACF\Exception Throws error if translations is not valid.
25+ * @param string $translations The translations value to set.
26+ * @return self
27+ */
28+ public function set_translations ( string $ translations ) {
29+ $ category = \acf_get_field_type_prop ( $ this ->type , 'category ' );
30+ if ( 'layout ' === $ category ) {
31+ throw new \Geniem \ACF \Exception ( self ::class . ': set_translations() can \'t be called on this field type. ' );
32+ }
33+
34+ $ choices = [ 'ignore ' , 'copy_once ' , 'sync ' ];
35+ switch ( $ this ->type ) {
36+ case 'text ' :
37+ case 'textarea ' :
38+ case 'wysiwyg ' :
39+ case 'oembed ' :
40+ case 'url ' :
41+ case 'email ' :
42+ $ choices [] = 'translate ' ;
43+ break ;
44+ }
45+
46+ if ( ! \in_array ( $ translations , $ choices ) ) {
47+ throw new \Geniem \ACF \Exception ( self ::class . ': set_translations() does not accept argument " ' . $ translations . '" ' );
48+ }
49+
50+ $ this ->translations = $ translations ;
51+
52+ return $ this ;
53+ }
54+
55+ /**
56+ * Get the field translations value
57+ *
58+ * @return string
59+ */
60+ public function get_translations () {
61+ return $ this ->translations ;
62+ }
63+ }
You can’t perform that action at this time.
0 commit comments