Projet

Général

Profil

Paste
Télécharger (6,71 ko) Statistiques
| Branche: | Révision:

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

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

    
7
/**
8
 * Panelizer Entity node plugin class.
9
 *
10
 * Handles node specific functionality for Panelizer.
11
 */
12
class PanelizerEntityNode extends PanelizerEntityDefault {
13
  /**
14
   * True if the entity supports revisions.
15
   */
16
  public $supports_revisions = TRUE;
17
  public $entity_admin_root = 'admin/structure/types/manage/%panelizer_node_type';
18
  public $entity_admin_bundle = 4;
19
  public $views_table = 'node';
20
  public $uses_page_manager = TRUE;
21

    
22
  public function entity_access($op, $entity) {
23
    // This must be implemented by the extending clas.
24
    return node_access($op, $entity);
25
  }
26

    
27
  /**
28
   * Implement the save function for the entity.
29
   */
30
  public function entity_save($entity) {
31
    node_save($entity);
32
  }
33

    
34
  public function entity_identifier($entity) {
35
    return t('This node');
36
  }
37

    
38
  public function entity_bundle_label() {
39
    return t('Node type');
40
  }
41

    
42
  /**
43
   * Determine if the entity allows revisions.
44
   */
45
  public function entity_allows_revisions($entity) {
46
    $retval = array();
47

    
48
    list($entity_id, $revision_id, $bundle) = entity_extract_ids($this->entity_type, $entity);
49

    
50
    $node_options = variable_get('node_options_' . $bundle, array('status', 'promote'));
51
    $retval[0] = in_array('revision', $node_options);
52
    $retval[1] = user_access('administer nodes');
53

    
54
    return $retval;
55
  }
56

    
57
  public function settings_form(&$form, &$form_state) {
58
    parent::settings_form($form, $form_state);
59

    
60
    $warn = FALSE;
61
    foreach ($this->plugin['bundles'] as $info) {
62
      if (!empty($info['status']) && !empty($info['view modes']['page_manager']['status'])) {
63
        $warn = TRUE;
64
        break;
65
      }
66
    }
67

    
68
    if ($warn) {
69
      $task = page_manager_get_task('node_view');
70
      if (!empty($task['disabled'])) {
71
        drupal_set_message('The node template page is currently not enabled in page manager. You must enable this for Panelizer to be able to panelize nodes using the "Full page override" view mode.', 'warning');
72
      }
73

    
74
      $handler = page_manager_load_task_handler($task, '', 'node_view_panelizer');
75
      if (!empty($handler->disabled)) {
76
        drupal_set_message('The panelizer variant on the node template page is currently not enabled in page manager. You must enable this for Panelizer to be able to panelize nodes using the "Full page override" view mode.', 'warning');
77
      }
78
    }
79
  }
80

    
81
  function get_default_display($bundle, $view_mode) {
82
    $display = parent::get_default_display($bundle, $view_mode);
83
    // Add the node title to the display since we can't get that automatically.
84
    $display->title = '%node:title';
85

    
86
    // Add the node links, they probably would like these.
87
    $pane = panels_new_pane('node_links', 'node_links', TRUE);
88
    $pane->css['css_class'] = 'link-wrapper';
89
    $pane->configuration['build_mode'] = $view_mode;
90
    $pane->configuration['context'] = 'panelizer';
91

    
92
    // @todo -- submitted by does not exist as a pane! That's v. sad.
93
    $display->add_pane($pane, 'center');
94

    
95
    return $display;
96
  }
97

    
98
  /**
99
   * Implements a delegated hook_page_manager_handlers().
100
   *
101
   * This makes sure that all panelized entities have the proper entry
102
   * in page manager for rendering.
103
   */
104
  public function hook_default_page_manager_handlers(&$handlers) {
105
    $handler = new stdClass;
106
    $handler->disabled = FALSE; /* Edit this to true to make a default handler disabled initially */
107
    $handler->api_version = 1;
108
    $handler->name = 'node_view_panelizer';
109
    $handler->task = 'node_view';
110
    $handler->subtask = '';
111
    $handler->handler = 'panelizer_node';
112
    $handler->weight = -100;
113
    $handler->conf = array(
114
      'title' => t('Node panelizer'),
115
      'context' => 'argument_entity_id:node_1',
116
      'access' => array(),
117
    );
118
    $handlers['node_view_panelizer'] = $handler;
119

    
120
    return $handlers;
121
  }
122

    
123
  /**
124
   * Implements a delegated hook_form_alter.
125
   *
126
   * We want to add Panelizer settings for the bundle to the node type form.
127
   */
128
  public function hook_form_alter(&$form, &$form_state, $form_id) {
129
    if ($form_id == 'node_type_form') {
130
      if (isset($form['#node_type'])) {
131
        $bundle = $form['#node_type']->type;
132
        $this->add_bundle_setting_form($form, $form_state, $bundle, array('type'));
133
      }
134
    }
135
  }
136

    
137
  public function hook_page_alter(&$page) {
138
    if ($_GET['q'] == 'admin/structure/types' && !empty($page['content']['system_main']['node_table'])) {
139
      // shortcut
140
      $table = &$page['content']['system_main']['node_table'];
141
      // Modify the header.
142
      $table['#header'][1]['colspan'] = 5;
143

    
144
      // Since we can't tell what row a type is for, but we know that they
145
      // were generated in this order, go through the original types
146
      // list:
147
      $types = node_type_get_types();
148
      $names = node_type_get_names();
149
      $row_index = 0;
150
      foreach ($names as $bundle => $name) {
151
        $type = $types[$bundle];
152
        if (node_hook($type->type, 'form')) {
153
          $type_url_str = str_replace('_', '-', $type->type);
154
          if ($this->is_panelized($bundle) && panelizer_administer_entity_bundle($this, $bundle)) {
155
            $table['#rows'][$row_index][] = array('data' => l(t('panelizer'), 'admin/structure/types/manage/' . $type_url_str . '/panelizer'));
156
          }
157
          else {
158
            $table['#rows'][$row_index][] = array('data' => '');
159
          }
160
          // Update row index for next pass:
161
          $row_index++;
162
        }
163
      }
164
    }
165
  }
166

    
167
  public function preprocess_panelizer_view_mode(&$vars, $entity, $element, $panelizer, $info) {
168
    parent::preprocess_panelizer_view_mode($vars, $entity, $element, $panelizer, $info);
169

    
170
    if (!empty($entity->promote)) {
171
      $vars['classes_array'][] = 'node-promoted';
172
    }
173
    if (!empty($entity->sticky)) {
174
      $vars['classes_array'][] = 'node-sticky';
175
    }
176
    if (empty($entity->status)) {
177
      $vars['classes_array'][] = 'node-unpublished';
178
    }
179
  }
180

    
181
  /**
182
   * Implements hook_views_plugins_alter().
183
   */
184
  function hook_views_plugins_alter(&$plugins) {
185
    // While it would be nice to genericize this plugin, there is no
186
    // generic entity view. This means that to genericize it we'll still
187
    // need to have each entity know how to do the view individually.
188
    // @todo make this happen.
189
    $path = drupal_get_path('module', 'panelizer') . '/plugins/views';
190
    $plugins['row']['panelizer_node_view'] = array(
191
      'title' => t('Panelizer display'),
192
      'help' => t('Render entities using the panels display for any that have been panelized.'),
193
      'handler' => 'panelizer_plugin_row_panelizer_node_view',
194
      'parent' => 'node',
195
      'base' => array('node'),
196
      'path' => $path,
197
      'uses options' => TRUE,
198
      'type' => 'normal',
199
      'register theme' => FALSE,
200
      'name' => 'panelizer_node_view',
201
    );
202
  }
203
}