Projet

Général

Profil

Paste
Télécharger (3,9 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / panelizer / plugins / entity / PanelizerEntityTaxonomyTerm.class.php @ 76df55b7

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 entity_access($op, $entity) {
19
    // This must be implemented by the extending class.
20
    if ($op == 'update' || $op == 'delete') {
21
      return taxonomy_term_edit_access($entity);
22
    }
23

    
24
    if ($op == 'view') {
25
      return TRUE;
26
    }
27

    
28
    return FALSE;
29
  }
30

    
31
  /**
32
   * Implement the save function for the entity.
33
   */
34
  public function entity_save($entity) {
35
    taxonomy_term_save($entity);
36
  }
37

    
38
  public function settings_form(&$form, &$form_state) {
39
    parent::settings_form($form, $form_state);
40

    
41
    $warn = FALSE;
42
    foreach ($this->plugin['bundles'] as $info) {
43
      if (!empty($info['status']) && !empty($info['view modes']['page_manager']['status'])) {
44
        $warn = TRUE;
45
        break;
46
      }
47
    }
48

    
49
    if ($warn) {
50
      $task = page_manager_get_task('term_view');
51
      if (!empty($task['disabled'])) {
52
        drupal_set_message('The taxonomy term template page is currently not enabled in page manager. You must enable this for Panelizer to be able to panelize taxonomy terms using the "Full page override" view mode.', 'warning');
53
      }
54

    
55
      $handler = page_manager_load_task_handler($task, '', 'term_view_panelizer');
56
      if (!empty($handler->disabled)) {
57
        drupal_set_message('The panelizer variant on the taxonomy term template page is currently not enabled in page manager. You must enable this for Panelizer to be able to panelize taxonomy terms using the "Full page override" view mode.', 'warning');
58
      }
59
    }
60
  }
61

    
62
  public function entity_identifier($entity) {
63
    return t('This taxonomy term');
64
  }
65

    
66
  public function entity_bundle_label() {
67
    return t('Taxonomy vocabulary');
68
  }
69

    
70
  function get_default_display($bundle, $view_mode) {
71
    // For now we just go with the empty display.
72
    // @todo come up with a better default display.
73
    return parent::get_default_display($bundle, $view_mode);
74
  }
75

    
76
  /**
77
   * Implements a delegated hook_page_manager_handlers().
78
   *
79
   * This makes sure that all panelized entities have the proper entry
80
   * in page manager for rendering.
81
   */
82
  public function hook_default_page_manager_handlers(&$handlers) {
83
    page_manager_get_task('term_view');
84

    
85
    $handler = new stdClass;
86
    $handler->disabled = FALSE; /* Edit this to true to make a default handler disabled initially */
87
    $handler->api_version = 1;
88
    $handler->name = 'term_view_panelizer';
89
    $handler->task = 'term_view';
90
    $handler->subtask = '';
91
    $handler->handler = 'panelizer_node';
92
    $handler->weight = -100;
93
    $handler->conf = array(
94
      'title' => t('Term panelizer'),
95
      'context' => page_manager_term_view_get_type() == 'multiple' ? 'argument_terms_1' : 'argument_term_1',
96
      'access' => array(),
97
    );
98
    $handlers['term_view_panelizer'] = $handler;
99

    
100
    return $handlers;
101
  }
102

    
103
  /**
104
   * Implements a delegated hook_form_alter.
105
   *
106
   * We want to add Panelizer settings for the bundle to the node type form.
107
   */
108
  public function hook_form_alter(&$form, &$form_state, $form_id) {
109
    if ($form_id == 'taxonomy_form_vocabulary') {
110
      if (isset($form['#vocabulary'])) {
111
        $bundle = $form['#vocabulary']->machine_name;
112
        $this->add_bundle_setting_form($form, $form_state, $bundle, array('machine_name'));
113
      }
114
    }
115
  }
116

    
117
  /**
118
   * Fetch the entity out of a build for hook_entity_view.
119
   *
120
   * @param $build
121
   *   The render array that contains the entity.
122
   */
123
  public function get_entity_view_entity($build) {
124
    $element = '#term';
125
    if (isset($build[$element])) {
126
      return $build[$element];
127
    }
128
  }
129

    
130
}