Projet

Général

Profil

Paste
Télécharger (5,17 ko) Statistiques
| Branche: | Révision:

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

1
<?php
2

    
3
class ctools_custom_content_ui extends ctools_export_ui {
4

    
5
  public 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['title_heading'] = array(
27
      '#title' => t('Title heading'),
28
      '#type' => 'select',
29
      '#default_value' => isset($form_state['item']->settings['title_heading']) ? $form_state['item']->settings['title_heading'] : 'h2',
30
      '#options' => array(
31
        'h1' => t('h1'),
32
        'h2' => t('h2'),
33
        'h3' => t('h3'),
34
        'h4' => t('h4'),
35
        'h5' => t('h5'),
36
        'h6' => t('h6'),
37
        'div' => t('div'),
38
        'span' => t('span'),
39
      ),
40
    );
41

    
42
    $form['body'] = array(
43
      '#type' => 'text_format',
44
      '#title' => t('Body'),
45
      '#default_value' => $form_state['item']->settings['body'],
46
      '#format' => $form_state['item']->settings['format'],
47
    );
48

    
49
    $form['substitute'] = array(
50
      '#type' => 'checkbox',
51
      '#title' => t('Use context keywords'),
52
      '#description' => t('If checked, context keywords will be substituted in this content.'),
53
      '#default_value' => !empty($form_state['item']->settings['substitute']),
54
    );
55
  }
56

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

    
60
    // Since items in our settings are not in the schema, we have to do these manually:
61
    $form_state['item']->settings['title'] = $form_state['values']['title'];
62
    $form_state['item']->settings['title_heading'] = $form_state['values']['title_heading'];
63
    $form_state['item']->settings['body'] = $form_state['values']['body']['value'];
64
    $form_state['item']->settings['format'] = $form_state['values']['body']['format'];
65
    $form_state['item']->settings['substitute'] = $form_state['values']['substitute'];
66
  }
67

    
68
  public function list_form(&$form, &$form_state) {
69
    parent::list_form($form, $form_state);
70

    
71
    $options = array('all' => t('- All -'));
72
    foreach ($this->items as $item) {
73
      $options[$item->category] = $item->category;
74
    }
75

    
76
    $form['top row']['category'] = array(
77
      '#type' => 'select',
78
      '#title' => t('Category'),
79
      '#options' => $options,
80
      '#default_value' => 'all',
81
      '#weight' => -10,
82
    );
83
  }
84

    
85
  public function list_filter($form_state, $item) {
86
    if ($form_state['values']['category'] != 'all' && $form_state['values']['category'] != $item->category) {
87
      return TRUE;
88
    }
89

    
90
    return parent::list_filter($form_state, $item);
91
  }
92

    
93
  public function list_sort_options() {
94
    return array(
95
      'disabled' => t('Enabled, title'),
96
      'title' => t('Title'),
97
      'name' => t('Name'),
98
      'category' => t('Category'),
99
      'storage' => t('Storage'),
100
    );
101
  }
102

    
103
  public function list_build_row($item, &$form_state, $operations) {
104
    // Set up sorting.
105
    switch ($form_state['values']['order']) {
106
      case 'disabled':
107
        $this->sorts[$item->name] = empty($item->disabled) . $item->admin_title;
108
        break;
109

    
110
      case 'title':
111
        $this->sorts[$item->name] = $item->admin_title;
112
        break;
113

    
114
      case 'name':
115
        $this->sorts[$item->name] = $item->name;
116
        break;
117

    
118
      case 'category':
119
        $this->sorts[$item->name] = $item->category;
120
        break;
121

    
122
      case 'storage':
123
        $this->sorts[$item->name] = $item->type . $item->admin_title;
124
        break;
125
    }
126

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

    
129
    $this->rows[$item->name] = array(
130
      'data' => array(
131
        array('data' => check_plain($item->name), 'class' => array('ctools-export-ui-name')),
132
        array('data' => check_plain($item->admin_title), 'class' => array('ctools-export-ui-title')),
133
        array('data' => check_plain($item->category), 'class' => array('ctools-export-ui-category')),
134
        array('data' => $ops, 'class' => array('ctools-export-ui-operations')),
135
      ),
136
      'title' => check_plain($item->admin_description),
137
      'class' => array(!empty($item->disabled) ? 'ctools-export-ui-disabled' : 'ctools-export-ui-enabled'),
138
    );
139
  }
140

    
141
  public function list_table_header() {
142
    return array(
143
      array('data' => t('Name'), 'class' => array('ctools-export-ui-name')),
144
      array('data' => t('Title'), 'class' => array('ctools-export-ui-title')),
145
      array('data' => t('Category'), 'class' => array('ctools-export-ui-category')),
146
      array('data' => t('Operations'), 'class' => array('ctools-export-ui-operations')),
147
    );
148
  }
149

    
150
}