root / drupal7 / sites / all / modules / panelizer / plugins / entity / PanelizerEntityTaxonomyTerm.class.php @ a2bb1a14
1 |
<?php
|
---|---|
2 |
/**
|
3 |
* @file
|
4 |
* Class for the Panelizer taxonomy term entity plugin.
|
5 |
*/
|
6 |
|
7 |
/**
|
8 |
* Panelizer Entity taxonomy term plugin class.
|
9 |
*
|
10 |
* Handles term specific functionality for Panelizer.
|
11 |
*/
|
12 |
class PanelizerEntityTaxonomyTerm extends PanelizerEntityDefault { |
13 |
public $entity_admin_root = 'admin/structure/taxonomy/%'; |
14 |
public $entity_admin_bundle = 3; |
15 |
public $views_table = 'taxonomy_term_data'; |
16 |
public $uses_page_manager = TRUE; |
17 |
|
18 |
public function init($plugin) { |
19 |
if (module_exists('taxonomy_revision')) { |
20 |
$this->supports_revisions = TRUE; |
21 |
} |
22 |
parent::init($plugin); |
23 |
} |
24 |
|
25 |
public function entity_access($op, $entity) { |
26 |
// This must be implemented by the extending class.
|
27 |
if ($op == 'update' || $op == 'delete') { |
28 |
return taxonomy_term_edit_access($entity); |
29 |
} |
30 |
|
31 |
if ($op == 'view') { |
32 |
return TRUE; |
33 |
} |
34 |
|
35 |
return FALSE; |
36 |
} |
37 |
|
38 |
/**
|
39 |
* Implement the save function for the entity.
|
40 |
*/
|
41 |
public function entity_save($entity) { |
42 |
taxonomy_term_save($entity);
|
43 |
} |
44 |
|
45 |
public function entity_identifier($entity) { |
46 |
return t('This taxonomy term'); |
47 |
} |
48 |
|
49 |
public function entity_bundle_label() { |
50 |
return t('Taxonomy vocabulary'); |
51 |
} |
52 |
|
53 |
function get_default_display($bundle, $view_mode) { |
54 |
// For now we just go with the empty display.
|
55 |
// @todo come up with a better default display.
|
56 |
return parent::get_default_display($bundle, $view_mode); |
57 |
} |
58 |
|
59 |
/**
|
60 |
* Implements a delegated hook_page_manager_handlers().
|
61 |
*
|
62 |
* This makes sure that all panelized entities have the proper entry
|
63 |
* in page manager for rendering.
|
64 |
*/
|
65 |
public function hook_default_page_manager_handlers(&$handlers) { |
66 |
page_manager_get_task('term_view');
|
67 |
|
68 |
$handler = new stdClass; |
69 |
$handler->disabled = FALSE; /* Edit this to true to make a default handler disabled initially */ |
70 |
$handler->api_version = 1; |
71 |
$handler->name = 'term_view_panelizer'; |
72 |
$handler->task = 'term_view'; |
73 |
$handler->subtask = ''; |
74 |
$handler->handler = 'panelizer_node'; |
75 |
$handler->weight = -100; |
76 |
$handler->conf = array( |
77 |
'title' => t('Term panelizer'), |
78 |
'context' => page_manager_term_view_get_type() == 'multiple' ? 'argument_terms_1' : 'argument_term_1', |
79 |
'access' => array(), |
80 |
); |
81 |
$handlers['term_view_panelizer'] = $handler; |
82 |
|
83 |
return $handlers; |
84 |
} |
85 |
|
86 |
/**
|
87 |
* Implements a delegated hook_form_alter.
|
88 |
*
|
89 |
* We want to add Panelizer settings for the bundle to the node type form.
|
90 |
*/
|
91 |
public function hook_form_alter(&$form, &$form_state, $form_id) { |
92 |
if ($form_id == 'taxonomy_form_vocabulary') { |
93 |
if (isset($form['#vocabulary'])) { |
94 |
$bundle = $form['#vocabulary']->machine_name; |
95 |
$this->add_bundle_setting_form($form, $form_state, $bundle, array('machine_name')); |
96 |
} |
97 |
} |
98 |
} |
99 |
|
100 |
/**
|
101 |
* Fetch the entity out of a build for hook_entity_view.
|
102 |
*
|
103 |
* @param $build
|
104 |
* The render array that contains the entity.
|
105 |
*/
|
106 |
public function get_entity_view_entity($build) { |
107 |
$element = '#term'; |
108 |
if (isset($build[$element])) { |
109 |
return $build[$element]; |
110 |
} |
111 |
} |
112 |
|
113 |
/**
|
114 |
* Obtain the machine name of the Page Manager task.
|
115 |
*
|
116 |
* The Page Manager task for the taxonomy_term entity is "term_view", and not
|
117 |
* the expected "taxonomy_term_view".
|
118 |
*/
|
119 |
public function get_page_manager_task_name() { |
120 |
if (empty($this->plugin['uses page manager'])) { |
121 |
return FALSE; |
122 |
} |
123 |
else {
|
124 |
return 'term_view'; |
125 |
} |
126 |
} |
127 |
|
128 |
/**
|
129 |
* Identify whether page manager is enabled for this entity type.
|
130 |
*
|
131 |
* Need to override this as Page Manager uses a different string for taxonomy
|
132 |
* terms than other entities.
|
133 |
*/
|
134 |
public function is_page_manager_enabled() { |
135 |
return variable_get('page_manager_term_view_disabled', TRUE); |
136 |
} |
137 |
|
138 |
} |