1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Silk\Taxonomy; |
4
|
|
|
|
5
|
|
|
use Silk\Type\Builder as TypeBuilder; |
6
|
|
|
use Silk\Taxonomy\Exception\InvalidTaxonomyNameException; |
7
|
|
|
|
8
|
|
|
class Builder extends TypeBuilder |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* Object types this taxonomy will be registered for |
12
|
|
|
* @var array |
13
|
|
|
*/ |
14
|
|
|
protected $objectTypes = []; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Default taxonomy labels |
18
|
|
|
* @var array |
19
|
|
|
*/ |
20
|
|
|
protected $labelDefaults = [ |
21
|
|
|
'add_new_item' => 'Add New {one}', |
22
|
|
|
'add_or_remove_items' => null, |
23
|
|
|
'all_items' => 'All {many}', |
24
|
|
|
'archives' => 'All {many}', |
25
|
|
|
'choose_from_most_used' => null, |
26
|
|
|
'edit_item' => 'Edit {one}', |
27
|
|
|
'items_list_navigation' => '{many} list navigation', |
28
|
|
|
'items_list' => '{many} list', |
29
|
|
|
'menu_name' => '{many}', |
30
|
|
|
'name_admin_bar' => '{one}', |
31
|
|
|
'name' => '{many}', |
32
|
|
|
'new_item_name' => 'New {one} Name', |
33
|
|
|
'no_terms' => 'No {many}', |
34
|
|
|
'not_found' => 'No {many} found.', |
35
|
|
|
'parent_item_colon' => 'Parent {one}:', |
36
|
|
|
'parent_item' => 'Parent {one}', |
37
|
|
|
'popular_items' => null, |
38
|
|
|
'search_items' => 'Search {many}', |
39
|
|
|
'separate_items_with_commas' => null, |
40
|
|
|
'singular_name' => '{one}', |
41
|
|
|
'update_item' => 'Update {one}', |
42
|
|
|
'view_item' => 'View {one}', |
43
|
|
|
]; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Specify which object types the taxonomy is for. |
47
|
|
|
* |
48
|
|
|
* @param string|array $types A list of object types or an array. |
49
|
|
|
* |
50
|
|
|
* @return $this |
51
|
|
|
*/ |
52
|
|
|
public function forTypes($types) |
53
|
|
|
{ |
54
|
|
|
$this->objectTypes = is_array($types) ? $types : func_get_args(); |
55
|
|
|
|
56
|
|
|
return $this; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Register and return the new taxonomy. |
61
|
|
|
* |
62
|
|
|
* @throws InvalidTaxonomyNameException |
63
|
|
|
* |
64
|
|
|
* @return Taxonomy |
65
|
|
|
*/ |
66
|
|
|
public function register() |
67
|
|
|
{ |
68
|
|
|
if (! $this->id || strlen($this->id) > 32) { |
69
|
|
|
throw new InvalidTaxonomyNameException('Taxonomy names must be between 1 and 32 characters in length.'); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
register_taxonomy($this->id, $this->objectTypes, $this->assembleArgs()); |
73
|
|
|
|
74
|
|
|
return Taxonomy::load($this->id); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|