Project

General

Profile

Paste
Download (3.36 KB) Statistics
| Branch: | Revision:

root / drupal7 / sites / all / modules / file_entity / plugins / entity / PanelizerEntityFile.class.php @ 1f142f4f

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

    
7
/**
8
 * Panelizer Entity file plugin class.
9
 *
10
 * Handles file specific functionality for Panelizer.
11
 */
12
class PanelizerEntityFile extends PanelizerEntityDefault {
13
  public $entity_admin_root = 'admin/structure/file-types/%';
14
  public $entity_admin_bundle = 3;
15
  public $views_table = 'file_managed';
16

    
17
  public function entity_access($op, $entity) {
18
    return file_entity_access($op, $entity);
19
  }
20

    
21
  /**
22
   * Implement the save function for the entity.
23
   */
24
  public function entity_save($entity) {
25
    file_save($entity);
26
  }
27

    
28
  /**
29
   * Implement the save function for the entity.
30
   */
31
  public function entity_allows_revisions($entity) {
32
    return array(FALSE, FALSE);
33

    
34
  }
35

    
36
  public function settings_form(&$form, &$form_state) {
37
    parent::settings_form($form, $form_state);
38

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

    
47
    if ($warn) {
48
      $task = page_manager_get_task('file_view');
49
      if (!empty($task['disabled'])) {
50
        drupal_set_message('The file template page is currently not enabled in page manager. You must enable this for Panelizer to be able to panelize files.', 'warning');
51
      }
52

    
53
      $handler = page_manager_load_task_handler($task, '', 'file_view_panelizer');
54
      if (!empty($handler->disabled)) {
55
        drupal_set_message('The panelizer variant on the file template page is currently not enabled in page manager. You must enable this for Panelizer to be able to panelize files.', 'warning');
56
      }
57
    }
58
  }
59

    
60
  public function entity_identifier($entity) {
61
    return t('This file');
62
  }
63

    
64
  public function entity_bundle_label() {
65
    return t('File type');
66
  }
67

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

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

    
83
    $handler = new stdClass;
84
    $handler->disabled = FALSE; /* Edit this to true to make a default handler disabled initially */
85
    $handler->api_version = 1;
86
    $handler->name = 'file_view_panelizer';
87
    $handler->task = 'file_view';
88
    $handler->subtask = '';
89
    $handler->handler = 'panelizer_node';
90
    $handler->weight = -100;
91
    $handler->conf = array(
92
      'title' => t('File panelizer'),
93
      'context' => 'argument_entity_id:file_1',
94
      'access' => array(),
95
    );
96
    $handlers['file_view_panelizer'] = $handler;
97

    
98
    return $handlers;
99
  }
100

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

    
115
  public function hook_page_alter(&$page) {
116

    
117
  }
118

    
119
  public function hook_views_plugins_alter(&$plugins) {
120

    
121
  }
122

    
123
}