Projet

Général

Profil

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

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

1
<?php
2
/**
3
 * @file
4
 * Class for the Panelizer taxonomy term entity plugin.
5
 */
6

    
7
/**
8
 * Panelizer Entity user plugin class.
9
 *
10
 * Handles user specific functionality for Panelizer.
11
 */
12
class PanelizerEntityUser extends PanelizerEntityDefault {
13
  public $entity_admin_root = 'admin/config/people/accounts';
14
  // No bundle support so we hardcode the default bundle.
15
  public $entity_admin_bundle = 'user';
16
  public $views_table = 'users';
17
  public $uses_page_manager = TRUE;
18

    
19
  public function entity_access($op, $entity) {
20
    // This must be implemented by the extending class.
21
    if ($op == 'update' || $op == 'delete') {
22
      return user_edit_access($entity);
23
    }
24

    
25
    if ($op == 'view') {
26
      return user_view_access($entity);
27
    }
28

    
29
    return FALSE;
30
  }
31

    
32
  /**
33
   * Implement the save function for the entity.
34
   */
35
  public function entity_save($entity) {
36
    // IMPORTANT NOTE: this can *only* update panelizer items!
37
    user_save($entity, array('panelizer' => $entity->panelizer));
38
  }
39

    
40
  public function settings_form(&$form, &$form_state) {
41
    parent::settings_form($form, $form_state);
42

    
43
    if (!empty($this->plugin['bundles']['user']['status']) && !empty($this->plugin['bundles']['user']['view modes']['page_manager']['status'])) {
44
      $task = page_manager_get_task('user_view');
45
      if (!empty($task['disabled'])) {
46
        drupal_set_message('The user template page is currently not enabled in page manager. You must enable this for Panelizer to be able to panelize users using the "Full page override" view mode.', 'warning');
47
      }
48

    
49
      $handler = page_manager_load_task_handler($task, '', 'user_view_panelizer');
50
      if (!empty($handler->disabled)) {
51
        drupal_set_message('The panelizer variant on the user template page is currently not enabled in page manager. You must enable this for Panelizer to be able to panelize users using the "Full page override" view mode.', 'warning');
52
      }
53
    }
54
  }
55

    
56
  public function entity_identifier($entity) {
57
    return t('This user');
58
  }
59

    
60
  public function entity_bundle_label() {
61
    return t('User');
62
  }
63

    
64
  function get_default_display($bundle, $view_mode) {
65
    // For now we just go with the empty display.
66
    // @todo come up with a better default display.
67
    return parent::get_default_display($bundle, $view_mode);
68
  }
69

    
70
  /**
71
   * Implements a delegated hook_page_manager_handlers().
72
   *
73
   * This makes sure that all panelized entities have the proper entry
74
   * in page manager for rendering.
75
   */
76
  public function hook_default_page_manager_handlers(&$handlers) {
77
    $handler = new stdClass;
78
    $handler->disabled = FALSE; /* Edit this to true to make a default handler disabled initially */
79
    $handler->api_version = 1;
80
    $handler->name = 'user_view_panelizer';
81
    $handler->task = 'user_view';
82
    $handler->subtask = '';
83
    $handler->handler = 'panelizer_node';
84
    $handler->weight = -100;
85
    $handler->conf = array(
86
      'title' => t('User panelizer'),
87
      'context' => 'argument_entity_id:user_1',
88
      'access' => array(),
89
    );
90
    $handlers['user_view_panelizer'] = $handler;
91

    
92
    return $handlers;
93
  }
94

    
95
  /**
96
   * Implements a delegated hook_form_alter.
97
   *
98
   * We want to add Panelizer settings for the bundle to the node type form.
99
   */
100
  public function hook_form_alter(&$form, &$form_state, $form_id) {
101
    if ($form_id == 'user_admin_settings') {
102
      $this->add_bundle_setting_form($form, $form_state, 'user', NULL);
103
    }
104
  }
105

    
106
  /**
107
   * Fetch the entity out of a build for hook_entity_view.
108
   *
109
   * @param $build
110
   *   The render array that contains the entity.
111
   */
112
  public function get_entity_view_entity($build) {
113
    $element = '#account';
114
    if (isset($build[$element])) {
115
      return $build[$element];
116
    }
117
  }
118

    
119
}