-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathTranslatable.php
More file actions
63 lines (55 loc) · 1.6 KB
/
Translatable.php
File metadata and controls
63 lines (55 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
/**
* ACF Codifier Translatable trait
*/
namespace Geniem\ACF\Field\Common;
/**
* Translatable trait
*/
trait Translatable {
/**
* The field translations value
*
* @var string
*/
protected $translations;
/**
* Set field translations value
*
* @see https://polylang.pro/doc/working-with-acf-pro/#customize-acf-fields
*
* @throws \Geniem\ACF\Exception Throws error if translations is not valid.
* @param string $translations The translations value to set.
* @return self
*/
public function set_translations( string $translations ) {
$category = \acf_get_field_type_prop( $this->type, 'category' );
if ( 'layout' === $category ) {
throw new \Geniem\ACF\Exception( self::class . ': set_translations() can\'t be called on this field type.' );
}
$choices = [ 'ignore', 'copy_once', 'sync' ];
switch ( $this->type ) {
case 'text':
case 'textarea':
case 'wysiwyg':
case 'oembed':
case 'url':
case 'email':
$choices[] = 'translate';
break;
}
if ( ! \in_array( $translations, $choices ) ) {
throw new \Geniem\ACF\Exception( self::class . ': set_translations() does not accept argument "' . $translations . '"' );
}
$this->translations = $translations;
return $this;
}
/**
* Get the field translations value
*
* @return string
*/
public function get_translations() {
return $this->translations;
}
}