Projet

Général

Profil

Paste
Télécharger (4,55 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / ctools / ctools_custom_content / plugins / export_ui / ctools_custom_content_ui.class.php @ 7fe061e8

1
<?php
2

    
3
class ctools_custom_content_ui extends ctools_export_ui {
4

    
5
  function edit_form(&$form, &$form_state) {
6
    // Correct for an error that came in because filter format changed.
7
    if (is_array($form_state['item']->settings['body'])) {
8
      $form_state['item']->settings['format'] = $form_state['item']->settings['body']['format'];
9
      $form_state['item']->settings['body'] = $form_state['item']->settings['body']['value'];
10
    }
11
    parent::edit_form($form, $form_state);
12

    
13
    $form['category'] = array(
14
      '#type' => 'textfield',
15
      '#title' => t('Category'),
16
      '#description' => t('What category this content should appear in. If left blank the category will be "Miscellaneous".'),
17
      '#default_value' => $form_state['item']->category,
18
    );
19

    
20
    $form['title'] = array(
21
      '#type' => 'textfield',
22
      '#default_value' => $form_state['item']->settings['title'],
23
      '#title' => t('Title'),
24
    );
25

    
26
    $form['body'] = array(
27
      '#type' => 'text_format',
28
      '#title' => t('Body'),
29
      '#default_value' => $form_state['item']->settings['body'],
30
      '#format' => $form_state['item']->settings['format'],
31
    );
32

    
33
    $form['substitute'] = array(
34
      '#type' => 'checkbox',
35
      '#title' => t('Use context keywords'),
36
      '#description' => t('If checked, context keywords will be substituted in this content.'),
37
      '#default_value' => !empty($form_state['item']->settings['substitute']),
38
    );
39
  }
40

    
41
  function edit_form_submit(&$form, &$form_state) {
42
    parent::edit_form_submit($form, $form_state);
43

    
44
    // Since items in our settings are not in the schema, we have to do these manually:
45
    $form_state['item']->settings['title'] = $form_state['values']['title'];
46
    $form_state['item']->settings['body'] = $form_state['values']['body']['value'];
47
    $form_state['item']->settings['format'] = $form_state['values']['body']['format'];
48
    $form_state['item']->settings['substitute'] = $form_state['values']['substitute'];
49
  }
50

    
51
  function list_form(&$form, &$form_state) {
52
    parent::list_form($form, $form_state);
53

    
54
    $options = array('all' => t('- All -'));
55
    foreach ($this->items as $item) {
56
      $options[$item->category] = $item->category;
57
    }
58

    
59
    $form['top row']['category'] = array(
60
      '#type' => 'select',
61
      '#title' => t('Category'),
62
      '#options' => $options,
63
      '#default_value' => 'all',
64
      '#weight' => -10,
65
    );
66
  }
67

    
68
  function list_filter($form_state, $item) {
69
    if ($form_state['values']['category'] != 'all' && $form_state['values']['category'] != $item->category) {
70
      return TRUE;
71
    }
72

    
73
    return parent::list_filter($form_state, $item);
74
  }
75

    
76
  function list_sort_options() {
77
    return array(
78
      'disabled' => t('Enabled, title'),
79
      'title' => t('Title'),
80
      'name' => t('Name'),
81
      'category' => t('Category'),
82
      'storage' => t('Storage'),
83
    );
84
  }
85

    
86
  function list_build_row($item, &$form_state, $operations) {
87
    // Set up sorting
88
    switch ($form_state['values']['order']) {
89
      case 'disabled':
90
        $this->sorts[$item->name] = empty($item->disabled) . $item->admin_title;
91
        break;
92
      case 'title':
93
        $this->sorts[$item->name] = $item->admin_title;
94
        break;
95
      case 'name':
96
        $this->sorts[$item->name] = $item->name;
97
        break;
98
      case 'category':
99
        $this->sorts[$item->name] = $item->category;
100
        break;
101
      case 'storage':
102
        $this->sorts[$item->name] = $item->type . $item->admin_title;
103
        break;
104
    }
105

    
106
    $ops = theme('links__ctools_dropbutton', array('links' => $operations, 'attributes' => array('class' => array('links', 'inline'))));
107

    
108
    $this->rows[$item->name] = array(
109
      'data' => array(
110
        array('data' => check_plain($item->name), 'class' => array('ctools-export-ui-name')),
111
        array('data' => check_plain($item->admin_title), 'class' => array('ctools-export-ui-title')),
112
        array('data' => check_plain($item->category), 'class' => array('ctools-export-ui-category')),
113
        array('data' => $ops, 'class' => array('ctools-export-ui-operations')),
114
      ),
115
      'title' => check_plain($item->admin_description),
116
      'class' => array(!empty($item->disabled) ? 'ctools-export-ui-disabled' : 'ctools-export-ui-enabled'),
117
    );
118
  }
119

    
120
  function list_table_header() {
121
    return array(
122
      array('data' => t('Name'), 'class' => array('ctools-export-ui-name')),
123
      array('data' => t('Title'), 'class' => array('ctools-export-ui-title')),
124
      array('data' => t('Category'), 'class' => array('ctools-export-ui-category')),
125
      array('data' => t('Operations'), 'class' => array('ctools-export-ui-operations')),
126
    );
127
  }
128

    
129
}